Re: [Tutor] help with Tkinter, please

2006-11-28 Thread Alan Gauld

"wesley chun" <[EMAIL PROTECTED]> wrote

> do the calculations.  if your operating system supports daemon
> threads, set your unimportant threads as daemon threads -- from the
> docs:
>
> "The entire Python program exits when no active non-daemon threads 
> are left."

Wes,
why do you recommend the use of daemons here?
Wouldn't that just leave a load of silently running daemon
threads eating up resources after the main program finishes?
I don't see the logic of that one? I'd have thought you wanted
to be sure all application threads died when the app died?

What am I missing?

Alan G.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with Tkinter, please

2006-11-28 Thread wesley chun
> > "The entire Python program exits when no active non-daemon threads
> > are left."
>
> why do you recommend the use of daemons here?
> Wouldn't that just leave a load of silently running daemon
> threads eating up resources after the main program finishes?
> I don't see the logic of that one? I'd have thought you wanted
> to be sure all application threads died when the app died?
>
> What am I missing?


are you missing something?  :-) i think there is a distinction bewteen
a daemon/server process and daemon threads.  i don't think that daemon
threads are spawned to a different process, save perhaps the ones
started from C.

i believe that as soon as there are only daemon threads left (a
complementary statement to the doc line above for Thread objects), the
Python interpreter will exit, killing them all. i think Python threads
are very similar to Java threads, but i'll let the thread experts
chime in here.

in the meantime, i googled for some references and found some good
(but perhaps long) reading:
http://www.quepublishing.com/articles/article.asp?p=26044&seqNum=8&rl=1
http://groups.google.com/group/comp.lang.python/browse_thread/thread/3da7545c655bd769
http://groups.google.com/group/comp.lang.python/browse_thread/thread/e8551fad6e06421f
http://groups.google.com/group/comp.lang.python/browse_thread/thread/ffa4edeca2a4fd60
http://mail.python.org/pipermail/python-list/2003-May/202288.html
http://groups.google.com/group/comp.lang.python/browse_thread/thread/8262b6e68481f1f9

hope this helps!
-- wes
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to connect to the SOAP server and make a request..........

2006-11-28 Thread Asrarahmed Kadri

Hi folks,


I am using SOAPpy module to make SOAP requests.

Can someone point me documentation that has list of functions that can be
used for carrying out various tasks.

Thanks in anticipation.

Best Regards,
Asrarahmed Kadri

--
To HIM you shall return.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to connect to the SOAP server and make a request..........

2006-11-28 Thread Simon Brunning
On 11/28/06, Asrarahmed Kadri <[EMAIL PROTECTED]> wrote:
> I am using SOAPpy module to make SOAP requests.
>
> Can someone point me documentation that has list of functions that can be
> used for carrying out various tasks.



-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with Tkinter, please

2006-11-28 Thread Kent Johnson
wesley chun wrote:
> if your operating system supports daemon
> threads, set your unimportant threads as daemon threads -- from the
> docs:
> 
> "The entire Python program exits when no active non-daemon threads are left."
> 
> http://docs.python.org/lib/thread-objects.html

AFAIK daemon threads are supported on all OSes that have Python thread 
support; the docs don't mention it being OS-specific and the threading 
module is written in Python so it should work wherever threads are 
supported.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Does Fredrik Lundh's console module work on Win XP?

2006-11-28 Thread Dick Moores
This seems it might be very useful. I just downloaded and thought I'd 
installed "console-1.1a1-20011229.win32-py2.5.exe"  in Python 2.5 in 
Win XP, but I can't get it to appear.

My attempts:
===
E:\Python25\Lib\site-packages>Console.py
Traceback (most recent call last):
   File "E:\Python25\Lib\site-packages\Console.py", line 34, in ?
 raise ImportError, "installation error: cannot find a console driver"
ImportError: installation error: cannot find a console driver

E:\Python25\Lib\site-packages>python Console.py
(silence)
==

Lundh says on http://effbot.org/zone/console-handbook.htm :

"The Console module provides a simple console interface, which 
provides cursor-addressable text output, plus support for keyboard 
and mouse input.

"The Console module is currently only available for Windows 95, 98, 
NT, and 2000. It probably works under Windows XP, but it hasn't been 
tested on that platform."

So DOES it work under Win XP? Or have I screwed something up?

Thanks,

Dick Moores

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with Tkinter, please

2006-11-28 Thread Kent Johnson
wesley chun wrote:
>>> "The entire Python program exits when no active non-daemon threads
>>> are left."
>> why do you recommend the use of daemons here?
>> Wouldn't that just leave a load of silently running daemon
>> threads eating up resources after the main program finishes?
>> I don't see the logic of that one? I'd have thought you wanted
>> to be sure all application threads died when the app died?
>>
>> What am I missing?
> 
> 
> are you missing something?  :-) i think there is a distinction bewteen
> a daemon/server process and daemon threads.  i don't think that daemon
> threads are spawned to a different process, save perhaps the ones
> started from C.
> 
> i believe that as soon as there are only daemon threads left (a
> complementary statement to the doc line above for Thread objects), the
> Python interpreter will exit, killing them all. i think Python threads
> are very similar to Java threads, but i'll let the thread experts
> chime in here.

Yes, that is correct. Daemon threads won't block the program from 
exiting. They will be stopped when the program exits - they are not 
separate processes.

However for the OP's application which is running calculations in the 
background in a GUI application, the threads will probably be created as 
needed and will end when the calculation is done. Unless the calculation 
is long enough that you want to be able to exit the app before the 
calculation completes, the thread doesn't really need to be a daemon.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Does Fredrik Lundh's console module work on Win XP?

2006-11-28 Thread Tim Golden
[Dick Moores]

| This seems it might be very useful. I just downloaded and thought I'd 
| installed "console-1.1a1-20011229.win32-py2.5.exe"  in Python 2.5 in 
| Win XP, but I can't get it to appear.
| 
| My attempts:
| ===
| E:\Python25\Lib\site-packages>Console.py
| Traceback (most recent call last):
|File "E:\Python25\Lib\site-packages\Console.py", line 34, in ?
|  raise ImportError, "installation error: cannot find a 
| console driver"
| ImportError: installation error: cannot find a console driver

Most likely bet here is that you don't have
Python25 linked to .py files. What does:

ftype python.file

show?

| 
| E:\Python25\Lib\site-packages>python Console.py
| (silence)
| ==

Do you mean it hung: didn't come back to the command
prompt? Or merely started, finished, and did nothing?
If the latter, then that's what I'd expect, since the
module does nothing except import things for you
to use from your own code.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] What is the meaning of using single underscore in front of variable name

2006-11-28 Thread Asrarahmed Kadri

Hi folks,

What does this mean?

_url = 'http://api.google.com/search/beta2'
_namespace = 'urn:GoogleSearch'


Single underscore as a prefix in variable naming...?? whats it for??

Any idea..

Regards,
Asrarahmed
--
To HIM you shall return.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is the meaning of using single underscore in front of variable name

2006-11-28 Thread Simon Brunning
On 11/28/06, Asrarahmed Kadri <[EMAIL PROTECTED]> wrote:
> What does this mean?
>
> _url = 'http://api.google.com/search/beta2'
> _namespace = 'urn:GoogleSearch'
>
> Single underscore as a prefix in variable naming...?? whats it for??

It means "private by convention" - see
.

-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] WHy use SOAPpy if we can do the things using httplib moduleRe: How to connect to the SOAP server and make a request..........

2006-11-28 Thread Asrarahmed Kadri

I read the URL suggested by Simon, In that URL, it is given how to create
the SOAP ENVELOPE using
httplib, so why bother about using SOAPpy...??

Any comments...

Best Regards,
Asrarahmed Kadri

On 11/28/06, Simon Brunning <[EMAIL PROTECTED]> wrote:


On 11/28/06, Asrarahmed Kadri <[EMAIL PROTECTED]> wrote:
> I am using SOAPpy module to make SOAP requests.
>
> Can someone point me documentation that has list of functions that can
be
> used for carrying out various tasks.



--
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/





--
To HIM you shall return.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Does Fredrik Lundh's console module work on Win XP?

2006-11-28 Thread Kent Johnson
Dick Moores wrote:
> This seems it might be very useful. I just downloaded and thought I'd 
> installed "console-1.1a1-20011229.win32-py2.5.exe"  in Python 2.5 in 
> Win XP, but I can't get it to appear.

It seems to work for me. Try this program, based on the example in the docs:

import Console

c = Console.getconsole()

c.title("Console Example")

c.text(0, 0, "here's some white text on white background", 0x1f)
c.text(10, 5, "line five, column ten")
c.text(1, 6, "press a key to exit")

c.getchar()


Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] WHy use SOAPpy if we can do the things using httplib moduleRe: How to connect to the SOAP server and make a request..........

2006-11-28 Thread Simon Brunning
On 11/28/06, Asrarahmed Kadri <[EMAIL PROTECTED]> wrote:
>
> I read the URL suggested by Simon, In that URL, it is given how to create
> the SOAP ENVELOPE using
> httplib, so why bother about using SOAPpy...??

The article discusses two ways of doing SOAP; by hand, and using
SOAPpy. Building the SOAP message by hand is part of the first
section, using SOAPpy is the second.

There's also a number of other article in the series:


-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] timeout a routine

2006-11-28 Thread arbaro arbaro
Hello,

I have a small problem with accessing a directory that may or may not exist.

- The program runs from a Linux OS. (though this shouldn't matter)
- A mountpoint /mnt/server may have been made to a windows server with samba.

I would like to find out if a folder on the server is reachable (eg.
/mnt/server/folderOnServer).
When I try to find out if dir exists with
os.path.isdir("/mnt/server/folderOnServer"), python hangs for a very
long time.

Is there a way to run the command
os.path.isdir("/mnt/server/folderOnServer"), and kill the attempt if
it tries for longer then 5 seconds?
Where/what can I use to accomplish something like this?


Thanks,
Arbaro
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2006-11-28 Thread Kopalle Narasimha
Hello, Everyone.

I have a strange problem with floating point numbers. Please help me.
I tried the following at the python prompt:

Case 1:
>>>  4.5/2.0 #Gives quotient
Answer: 2.25

Case 2:
>>>  4.5%2.0  #Gives Remainder
Answer: 0.5

How could a floating point division give a remainder???
I think the remainder must always be zero since the quotient would be
a floating point number.
When a similar program is written in C language(i.e. to get remainder
of two floating point numbers), I received an error supporting my
idea.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2006-11-28 Thread Noufal Ibrahim
Kopalle Narasimha wrote:
> Hello, Everyone.
> 
> I have a strange problem with floating point numbers. Please help me.
> I tried the following at the python prompt:
> 
> Case 1:
  4.5/2.0 #Gives quotient
> Answer: 2.25
> 
> Case 2:
  4.5%2.0  #Gives Remainder
> Answer: 0.5
> 

I don't think it's defined that way. When you say x%y, you are looking
for the remainder after when x is divided by y. The fractional part is a
remainder.
eg. a%b = c
4.5%2.0 = 0.5 because

2.0 * 2 + 0.5 = 4.5
(b * quotient) + c = a where quotient is not a fractional number.

It's discussed a little here http://docs.python.org/ref/binary.html



-- 
~noufal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Does Fredrik Lundh's console module work on Win XP?

2006-11-28 Thread Dick Moores
At 07:10 AM 11/28/2006, you wrote:
>Dick Moores wrote:
>>This seems it might be very useful. I just downloaded and thought 
>>I'd installed "console-1.1a1-20011229.win32-py2.5.exe"  in Python 
>>2.5 in Win XP, but I can't get it to appear.
>
>It seems to work for me. Try this program, based on the example in the docs:
>
>import Console
>
>c = Console.getconsole()
>
>c.title("Console Example")
>
>c.text(0, 0, "here's some white text on white background", 0x1f)
>c.text(10, 5, "line five, column ten")
>c.text(1, 6, "press a key to exit")
>
>c.getchar()

Yes, that works. I added styles to the 2nd 2 texts, and also added a 
rectangle with a style and a character. Everything works. But what's 
the point? How is this console useful? In games or animation?

Dick



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] timeout a routine

2006-11-28 Thread arbaro arbaro
Thanks a lot Jordan,

I have no experience with classes at all yet, so your example will
give me a really nice startting point.




On 11/28/06, Jordan Greenberg <[EMAIL PROTECTED]> wrote:
> arbaro arbaro wrote:
> > Hello,
> 
> > Is there a way to run the command
> > os.path.isdir("/mnt/server/folderOnServer"), and kill the attempt if
> > it tries for longer then 5 seconds?
> > Where/what can I use to accomplish something like this?
> >
> >
> > Thanks,
> > Arbaro
>
> Hi Arbaro!
> The only way I can think of is with threads.
> Its not too hard to use one thread to control another, and stop it after
> a certain amount of time. Something like this:
>
> #threadexample.py
>
> from threading import Thread
> import time
>
> MyThread(Thread):
> def __init__(self, message):
> self.message=message
> Thread.__init__(self)
> def run(self):
> while True:
> print "MyThread: "+self.message
>
> class Controller(Thread):
> def __init__(self, runner,time):
> self.runner=runner
> self.delta=time
> Thread.__init__(self)
>
> def run(self):
> self.start=time.time()
> self.runner.start()
> self.done=False
> while not self.done:
> if time.time() > (self.start+self.delta):
> print "Controller: Stopping MyThread."
> self.runner._Thread__stop()
> return
>
> mythread=MyThread("hello")
> control=Controller(mythread, 2)
> control.start()
>
> #end of threadexample.py
>
> I'm still just learning threading, so there is probably a better way to
> do this, though this seems to work pretty well.
>
>
> Hope this helps,
> Jordan Greenberg
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python for Kids

2006-11-28 Thread [EMAIL PROTECTED]
Hello,

I bought the book "Python for Kids". started to read it, but can not  
find where I have to install xturlte? I use macintosh... Have python  
2.5.
If someone knows where I have to copy the xturtle and other files  
(for xturle) on macintosh, will be happy for help:)

Thank You in advance,
Vladlena
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is the meaning of using single underscore in front ofvariable name

2006-11-28 Thread Alan Gauld
"Asrarahmed Kadri" <[EMAIL PROTECTED]> wrote

> Single underscore as a prefix in variable naming...?? whats it for??
>
> Any idea..

Its a convention to indicate that this variable is not for general 
use.
It is part of the internal implementation of the class or module.

But it is only a convention and Python will not stop you from
accessing it. It is similar to the convention of using all uppercase
letters to indicate a constant value that should not be changed
by users of the code.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Modulo operator (was no subject)

2006-11-28 Thread Bob Gailer
Please always provide a subject line. Otherwise it is very hard to 
follow threads.

Noufal Ibrahim wrote:
> Kopalle Narasimha wrote:
>   
>> Hello, Everyone.
>>
>> I have a strange problem with floating point numbers. Please help me.
>> I tried the following at the python prompt:
>>
>> Case 1:
>> 
>  4.5/2.0 #Gives quotient
>   
>> Answer: 2.25
>>
>> Case 2:
>> 
>  4.5%2.0  #Gives Remainder
>   
Despite what the documentation says, the modulo operator does not return 
a remainder! Notice:
 >>> [x % 3 for x in range(-5,5)]
[1, 2, 0, 1, 2, 0, 1, 2, 0, 1]
For negative values of the left argument the result is NOT the 
remainder. The literature seems very confused about this, using 
"remainder" when it is NOT the case. What's worse, in some languages the 
mod operator DOES return the remainder.

[snip]

-- 
Bob Gailer
510-978-4454

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Modulo operator (was no subject)

2006-11-28 Thread Bob Gailer
See http://en.wikipedia.org/wiki/Modular_arithmetic for a comprehensive 
discussion. Especially the paragraph title Remainders.

Often people ask "what's the practical use of modular arithmetic?" 
Consider how we tell time...

-- 
Bob Gailer
510-978-4454


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] WHy use SOAPpy if we can do the things using httplibmoduleRe: How to connect to the SOAP server and make arequest..........

2006-11-28 Thread Alan Gauld

"Asrarahmed Kadri" <[EMAIL PROTECTED]> wrote in message

>I read the URL suggested by Simon, In that URL, it is given how to 
>create
> the SOAP ENVELOPE using
> httplib, so why bother about using SOAPpy...??

You can also read web pages using http POST and GET messages
to a socket using the socket library, but most folks find it easier
to use urllib.

For that matter you can display output to sys.stdout, so
why bother with print?

The library functions make things easier and more consistent.
Somebody else has debugged the code so you don't have to...

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Test

2006-11-28 Thread Jordan Greenberg
Hey, my messages don't seem to be showing up on the list...
So if this one works, sorry for the test message, everybody!
My school just decided not to allow any outgoing email to any SMTP
server but their own *grumble* So I've been sending my tutor messages
through that server but with this address munged into the headers.
Seems to send messages through fine, but I guess the list doesn't like
it for some reason. If this message works, it'll be proof of that
(since this is from the gmail web interface) and I'll re-subscribe to
the list from my other address ([EMAIL PROTECTED]) so my messages
will come from there from now on.

Sorry again for the test,
Jordan Greenberg
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with Tkinter, please

2006-11-28 Thread Alan Gauld

"wesley chun" <[EMAIL PROTECTED]> wrote

>> why do you recommend the use of daemons here?
>> Wouldn't that just leave a load of silently running daemon
>> threads eating up resources
>
> are you missing something?  :-) i think there is a distinction 
> bewteen
> a daemon/server process and daemon threads.  i don't think that 
> daemon
> threads are spawned to a different process

Aha! That's what I was missing.
I assumed that daemon threads ran under the OS main thread
rather than the application main thread.

What exactly is the advantage of a daemon thread over a normal
one in that case - other than that the application will end while
daemons are still running? In fact that might be the advantage.
But in that case daemons would only be useful for endless
loop type threads?

So I still don't see why the OP should should them?

> are very similar to Java threads, but i'll let the thread experts
> chime in here.

Java threads, like so much of Java are things I try to avoid! :-)

Thanks for the pointers.

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] draw 3D using Tkinter?

2006-11-28 Thread linda.s
Is there any sample code to draw 3D using Tkinter?
Thanks,
Linda
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with Tkinter, please

2006-11-28 Thread wesley chun
> What exactly is the advantage of a daemon thread over a normal
> one in that case - other than that the application will end while
> daemons are still running? In fact that might be the advantage.
> But in that case daemons would only be useful for endless
> loop type threads?

for example, they can be worker threads, those that take some service
request, perform some work, produces results, then goes back to wait
for more work -- your endless loop scenario.  if the main thread is
taking user input and pawning off service requests to worker threads,
then exits, meaning no more possible work for the worker threads, they
should then be killed off along with the main thread. here's a snippet
from the 1st link i sent:

"Daemon threads are designed as low-level background threads that
perform useful work. However, it is not essential that they be allowed
to complete before an application terminates. One example of a daemon
thread is the garbage collector thread."

if the main (and other non-daemon) threads exit, there is no more code
allocating memory (thus no longer a need to GC memory... IOW, there's
no more work to be done), so there really isn't a reason for them
(daemon threads) to stay up and running.

the bottom line is that they can do work when work is available, but
other than that, are pretty useless without some non-daemon threads
providing that work for them; thus it's relatively harmless to kill
them off.

FWIW, when i first learned about daemon threads, i was also confused
at the naming and their relationship (if any) with daemon/server
processes even though they do similar things.  i guess that's what
makes it easy to reboot your *nix servers... you shutdown and/or
reboot without explicitly killing each server right?  it sure would
take a long time... can you imagine how many "/etc/init.d/XXX stop"
calls you'd have to make in your shell? :-)

HTH,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help

2006-11-28 Thread Mohammed H. Hafeji
Need some help in python.

How do i make the user choose wheter or not to pick it up? (i can do picking up 
an item from a list):

objectsCarried = []

inventory = ['bat']
lengthOfInventory =len(inventory)

print 'The room holds:'

for item in range(lengthOfInventory):
print item, inventory[item]


numberChosen = int(raw_input('use the number to pick up an item '))

objectChosen = inventory[numberChosen]

objectsCarried.append(objectChosen)
inventory.remove(objectChosen)

print 'you are carrying '
for item in objectsCarried:
print item

print

print 'The room now holds:'

for item in inventory:
print item
 
But i cant do when u have a choice to pick up or not.

Also if not too much trouble then how can i do: 
  
IF the user picks the bat up then when he comes across the vampire then he 
kills it, but if he hasnt pickd up the bat then he dies? 
  
Thanks in advance

P.S. Could u plz email sum code___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] WHy use SOAPpy if we can do the things using httplibmoduleRe: How to connect to the SOAP server and make arequest..........

2006-11-28 Thread wesley chun
> it is given how to
> >create
> > the SOAP ENVELOPE using
> > httplib, so why bother about using SOAPpy...??
>
> You can also read web pages using http POST and GET messages
> to a socket using the socket library, but most folks find it easier
> to use urllib.
>
> For that matter you can display output to sys.stdout, so
> why bother with print?
>
> The library functions make things easier and more consistent.
> Somebody else has debugged the code so you don't have to...


to further the analogy, you could say why bother with urllib and use
httplib instead, or forget all those and use TCP sockets, or drop TCP
in favor of UDP, or protocols?  who needs protocols?  just use raw
sockets!  (i'll stop here... you get the picture.) :-)

you're basically using high-level libraries as an abstraction layer
(to make developing apps easier) to hide the messiness of the
lower-level implementation and details which may not be applicable to
your work.  i mean, why use Python when you can do it in C?

-- wesley
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] WHy use SOAPpy if we can do the things using httplibmoduleRe: How to connect to the SOAP server and make arequest..........

2006-11-28 Thread Andreas Kostyrka
> you're basically using high-level libraries as an abstraction layer
> (to make developing apps easier) to hide the messiness of the
> lower-level implementation and details which may not be applicable to
> your work.  i mean, why use Python when you can do it in C?
Wimp! You can do it in binary machine code. (Assemblers are weakminded
compilers only) And you can even have the joy multiple times, porting
your app to half a dozen architectures that might be relevant :)

Andreas
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Game programming - inventory management (was Help)

2006-11-28 Thread Bob Gailer
Please use a meaningful subject line. Many of us try to follow 
"threads", and "help" does not help.
I have provided one for this case.

Mohammed H. Hafeji wrote:
> Need some help in python.
>  
> How do i make the user choose wheter or not to pick it up? (i can do 
> picking up an item from a list):
> //
> /*objectsCarried = []*/
> /**/ 
> /*inventory = ['bat']
> lengthOfInventory =len(inventory)*/
> /**/ 
> /*print 'The room holds:'*/
> /**/ 
> /*for item in range(lengthOfInventory):
> print item, inventory[item]*/
> /**/ 
>
> /*numberChosen = int(raw_input('use the number to pick up an item '))*/
> /**/ 
> /*objectChosen = inventory[numberChosen]*/
> /**/ 
> /*objectsCarried.append(objectChosen)
> inventory.remove(objectChosen)*/
> /**/ 
> /*print 'you are carrying '
> for item in objectsCarried:
> print item*/
> /**/ 
> /*print*/
> /**/ 
> /*print 'The room now holds:'*/
> /**/ 
> /*for item in inventory:
> print item*/
>  
> But i cant do when u have a choice to pick up or not.
>  
> Also if not too much trouble then how can i do:
>  
> IF the user picks the bat up then when he comes across the vampire 
> then he kills it, but if he hasnt pickd up the bat then he dies?
>  
> Thanks in advance
>  
> P.S. Could u plz email sum code
> 
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   


-- 
Bob Gailer
510-978-4454

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to generate permutations of a given string

2006-11-28 Thread Dick Moores
At 02:49 PM 11/27/2006, John Fouhy wrote:
>On 28/11/06, Carroll, Barry <[EMAIL PROTECTED]> wrote:
> > I'm not sure these qualify as "simple", but they work.  This was one of
> > my very first projects in Python, so it may be more complicated than
> > necessary.
>
>This is an alternative approach:
>http://mail.python.org/pipermail/tutor/2005-May/038059.html

However, this is not what someone looking for an anagram algorithm 
would find useful, it seems to me.

Barry Carroll offering does the job, if the last line is revised as 
shown below:

def permute(word):
 """
 By Barry Carrol <[EMAIL PROTECTED]>
 on Tutor list, revised (last line) by me.
 """
 retList=[]
 if len(word) == 1:
 # There is only one possible permutation
 retList.append(word)
 else:
 # Return a list of all permutations using all characters
 for pos in range(len(word)):
 # Get the permutations of the rest of the word
 permuteList=permute(word[0:pos]+word[pos+1:len(word)])
 # Now, tack the first char onto each word in the list
 # and add it to the output
 for item in permuteList:
 retList.append(word[pos]+item)
 #return retList
 return list(set(retList)) # make elements of retList unique

(The line in the code in Barry's post, 
"permuteList=permute2(word[0:pos]+word[pos+1:len(word)])", was 
corrected to "permuteList=permute(word[0:pos]+word[pos+1:len(word)])" 
in an email from him to me.)
(i.e., permute2 changed to permute)

Dick Moores

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] draw 3D using Tkinter?

2006-11-28 Thread Alan Gauld

"linda.s" <[EMAIL PROTECTED]> wrote 

> Is there any sample code to draw 3D using Tkinter?

I don't think so, native Tkinter isn't really the ideal graphics 
environment. Its not what it was designed for.

However there are almost certainly libraries around for 3D 
stuff that can use Tkinter, although I don't know of any myself.
Some of the plotting libraries might do it.

I think pyGame does 3D graphics but it uses wxPython not Tkinter.

Visual python (?) does 3D stuff too, but again I've never used it.

Alan G.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Extract from Word Doc

2006-11-28 Thread Steve Nelson
Hello,

Is there a way to pull "strings" out of a word document?  Not unlike
the way the UNIX command "strings" does?

I want this to be OS-portable, so shelling out is not an option.

I tried opening the word doc and then looking at it using the object's
methods, but it is all binary info, and can't be parsed.

Any suggestions?

S.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Extract from Word Doc

2006-11-28 Thread John Fouhy
On 29/11/06, Steve Nelson <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Is there a way to pull "strings" out of a word document?  Not unlike
> the way the UNIX command "strings" does?

Here's a crude attempt:

>>> import string
>>> s = file('myworddoc.doc').read()
>>> t = ''.join(c for c in s if c in
string.letters+string.digits+string.punctuation+string.whitespace)

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Angles

2006-11-28 Thread Carlos
Hello to All:

I'm trying to write a sun positioning system with the help of python. 
The idea is that you give the program a location, date and hour and it 
returns the position of the sun.

I found a webpage that details the math behind this 
(http://www.usc.edu/dept/architecture/mbs/tools/vrsolar/Help/solar_concepts.html)
 
, it was fairly trivial to translate this to python until I got to the 
azimuth equation. It looks like this:

x_azm   = sin(hour_R) * cos(decl_R)
y_azm   = (-(cos(hour_R))*cos(decl_R)*sin(lat_R))+(cos(lat_R)* sin(decl_R))
azimuth = atan(x_azm/y_azm)*TODEGREE

where:

Alt = Altitude
Azm = Azimuth
Decl= Declination
HAngle  = Hour angle
alt_R   = Altitude in radians
azm_R   = Azimuth in radians
lat_R   = Latitude in radians
hour_R  = Hour angle in radians
x_azm   = x component of azimuth
y_azm   = y component of azimuth
TODEGREE= Constant equal to 180/p

My python code for this particular equation:

from math import *

def Az(Lat, Dec, H_Ang):

lat_r = radians(Lat)
decl_r = radians(Dec)
hour_r  = radians(H_Ang)

x_azm = sin(hour_r) * cos(decl_r)
y_azm = (-(cos(hour_r)) * cos(decl_r) * sin(lat_r)) + 
(cos(lat_r) *  sin(decl_r))

Azimuth= degrees(atan(x_azm/y_azm))
Azimuth = Azimuth *(-1)
return Azimuth

I was never very good at trigonometry, but looks like my translation of 
the equation is ok and the problem is some kind of python behavior, 
because whenever the results exceed 100° (deg) Python returns the 
complementary angle, it is possible to avoid this? Or I'm overlooking 
somethig?

You can check this by yourself:

If you use Az(34, -21.67, -150) you will get 72.79, the result in the 
webpage tool will be 107.21. And 72.79 + 107.21 = 180
but if you use Az(34, -21.67, -150) you will get 54.88 in both, my 
script and the webpage tool.

If you want to take a look at the webpage tool this is the link: 
http://www.usc.edu/dept/architecture/mbs/tools/vrsolar/frameset.html

Thanks in advance for your help,
Carlos
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Why can't I import this?

2006-11-28 Thread Dick Moores
I just discovered something for Tkinter that I want to use. It's a 
Tooltip class, at  .

I've copied it to a file I named toolTipDemo.py and put it with a 
couple of other files I use as modules. They're in
E:\Python25\Lib\site-packages\mine. One file there is intSpell.py, 
and I can import it by

from mine.intSpell import intSpell

With no problem:
 >>> from mine.intSpell import intSpell
 >>>
However, the same method of importing doesn't work with toolTipDemo:
 >>> from mine.toolTipDemo import toolTipDemo
Traceback (most recent call last):
   File "", line 1, in 
ImportError: cannot import name toolTipDemo

I've tried various things, such as remarking out the whole demo at 
the bottom, but leaving

if __name__ == '__main__':
 #demo()
 pass

Any ideas on what I've done wrong?

BTW, toolTipDemo.py runs fine at the command line. I.e., the demo 
shows up nicely, with 2 tooltips.

Thanks,

Dick Moores

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to generate permutations of a given string

2006-11-28 Thread Carroll, Barry
Dick, et al:

> -Original Message-
> Date: Tue, 28 Nov 2006 12:57:51 -0800
> From: Dick Moores <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] How to generate permutations of a given string
> To: Python Tutor List 
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="us-ascii"; format=flowed
> 
> At 02:49 PM 11/27/2006, John Fouhy wrote:
> >On 28/11/06, Carroll, Barry <[EMAIL PROTECTED]> wrote:
> > > I'm not sure these qualify as "simple", but they work.  This was
one
> of
> > > my very first projects in Python, so it may be more complicated
than
> > > necessary.
> >
> >This is an alternative approach:
> >http://mail.python.org/pipermail/tutor/2005-May/038059.html
> 
> However, this is not what someone looking for an anagram algorithm
> would find useful, it seems to me.
> 
> Barry Carroll offering does the job, if the last line is revised as
> shown below:
> 
> def permute(word):
>  """
>  By Barry Carrol <[EMAIL PROTECTED]>
>  on Tutor list, revised (last line) by me.
>  """
>  retList=[]
>  if len(word) == 1:
>  # There is only one possible permutation
>  retList.append(word)
>  else:
>  # Return a list of all permutations using all
characters
>  for pos in range(len(word)):
>  # Get the permutations of the rest of the
word
> 
> permuteList=permute(word[0:pos]+word[pos+1:len(word)])
>  # Now, tack the first char onto each word in
the
> list
>  # and add it to the output
>  for item in permuteList:
>  retList.append(word[pos]+item)
>  #return retList
>  return list(set(retList)) # make elements of retList unique
> 
> (The line in the code in Barry's post,
> "permuteList=permute2(word[0:pos]+word[pos+1:len(word)])", was
> corrected to "permuteList=permute(word[0:pos]+word[pos+1:len(word)])"
> in an email from him to me.)
> (i.e., permute2 changed to permute)
> 
> Dick Moores
In the intrest of reusability, I would recommend leaving permute as it
is and calling it from another function:

#
> def permuteset(word):
> return list(set(permute(word)))

> permute("121")
> ['121', '112', '211', '211', '112', '121']

> permuteset("121")
> ['121', '211', '112']
#

If you're sure you will never want to use the permute function in any
other way, then it doesn't matter, of course.  Otherwise, it's nice to
have the original function intact, in case you ever want a list of all
the combinations that ARE duplicates, for example ;*)

FWIW.

Regards,

Barry

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] OT What's next

2006-11-28 Thread Amadeo Bellotti

I've recently wanted to learn more about my hardware and i figured what
better way then programming at the base level. I no it sounds stupid but i
would like to learn to manage my own memory. so i was wondering if anyone
has dipped there toe in either C or Assembly. If you have please tell me
which one you prefer and were a good site is
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Angles

2006-11-28 Thread Terry Carroll
On Tue, 28 Nov 2006, Carlos wrote:

> I was never very good at trigonometry, but looks like my translation of 
> the equation is ok and the problem is some kind of python behavior, 
> because whenever the results exceed 100? (deg) Python returns the 
> complementary angle, it is possible to avoid this? Or I'm overlooking 
> somethig?

Carlos, I'm not so good at trigonometry myself, but I suspect that the 
trouble is that for some trig functions, both an angle and that angle's 
complement map to the same value.  For example:

>>> angle1 = radians(45)  # 45 degrees
>>> angle2 = pi-angle1# 135 degrees
>>> print degrees(angle1), degrees(angle2)
45.0 135.0
>>> sin(angle1), sin(angle2)
(0.70710678118654746, 0.70710678118654757)
>>> angle1 = radians(30)
>>> angle2 = pi-angle1
>>> print degrees(angle1), degrees(angle2)
30.0 150.0
>>> sin(angle1), sin(angle2)
(0.49994, 0.49994)

So basically, once you take a sine in your early steps, you're getting the 
same sine result regardless of whether it's in the first quadrant (0-90 
degrees) or second quadrant (90-180 degrees).  When you subsequently use 
that sine and try to eventually get an angle out of it, it's going to give 
you a first-quadrant result.

I think you'll need to track the range of your input angle and adjust your 
output angle accordingly.  The algorithm you got may only be valid for 
0-90 degrees.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why can't I import this?

2006-11-28 Thread Kent Johnson
Dick Moores wrote:
> I just discovered something for Tkinter that I want to use. It's a 
> Tooltip class, at  .
> 
> I've copied it to a file I named toolTipDemo.py and put it with a 
> couple of other files I use as modules. They're in
> E:\Python25\Lib\site-packages\mine. One file there is intSpell.py, 
> and I can import it by
> 
> from mine.intSpell import intSpell
> 
> With no problem:
>  >>> from mine.intSpell import intSpell
>  >>>
> However, the same method of importing doesn't work with toolTipDemo:
>  >>> from mine.toolTipDemo import toolTipDemo
> Traceback (most recent call last):
>File "", line 1, in 
> ImportError: cannot import name toolTipDemo

Try
from mine.toolTipDemo import demo

mine.toolTipDemo points to the module, then you need to reference a name 
defined in the module. (You must have something called intSpell in 
intSpell.py.)

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why can't I import this?

2006-11-28 Thread Dick Moores
At 07:20 PM 11/28/2006, Kent Johnson wrote:
>Dick Moores wrote:
> > I just discovered something for Tkinter that I want to use. It's a
> > Tooltip class, at  .
> >
> > I've copied it to a file I named toolTipDemo.py and put it with a
> > couple of other files I use as modules. They're in
> > E:\Python25\Lib\site-packages\mine. One file there is intSpell.py,
> > and I can import it by
> >
> > from mine.intSpell import intSpell
> >
> > With no problem:
> >  >>> from mine.intSpell import intSpell
> >  >>>
> > However, the same method of importing doesn't work with toolTipDemo:
> >  >>> from mine.toolTipDemo import toolTipDemo
> > Traceback (most recent call last):
> >File "", line 1, in 
> > ImportError: cannot import name toolTipDemo
>
>Try
>from mine.toolTipDemo import demo
>
>mine.toolTipDemo points to the module, then you need to reference a name
>defined in the module. (You must have something called intSpell in
>intSpell.py.)

Interestingly (or not) it just hit me that I should try that, and it 
worked. So I suppose that if I want to use tooltips in a Tkinter 
program, I can just use  "from mine.toolTipDemo import *" and use 
what I need. (Haven't tried that yet, however.)

Thanks, Kent.

Dick

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Linux Distro Anyone

2006-11-28 Thread Amadeo Bellotti

I was thinking it would be really nice if i could make a Pocket Linux distro
that of course fits on one or two floppies (outdated I no but still are
amazing) thats just the Linux kernel, bash, and python. with of course a lot
of tiny scripts to do daily business and/or recovery. We could have a mail
client, a text reader/editor, text based web browser, all in python. Of
Course this will be a lot of work and it would be neat if the whole user
group pitched in. so what I'm basically asking is that if you are interested
email me and ill give you some detail.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why can't I import this?

2006-11-28 Thread Kent Johnson
Dick Moores wrote:
> At 07:20 PM 11/28/2006, Kent Johnson wrote:
>> Try
>>from mine.toolTipDemo import demo
>> mine.toolTipDemo points to the module, then you need to reference a name
>> defined in the module. (You must have something called intSpell in
>> intSpell.py.)
> 
> Interestingly (or not) it just hit me that I should try that, and it 
> worked. So I suppose that if I want to use tooltips in a Tkinter 
> program, I can just use  "from mine.toolTipDemo import *" and use 
> what I need. (Haven't tried that yet, however.)

Yes, you can do that but in general that style is not recommended. It 
makes it hard to figure out where names are defined and you can import 
more than you really want. Better is to just import what you want, e.g.
from mine.toolTipDemo import A, b, CC

or import the module with an alias:
import mine.toolTipDemo as TTD

then refer to e.g.
TTD.demo()

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Linux Distro Anyone

2006-11-28 Thread Dave Kuhlman
On Tue, Nov 28, 2006 at 10:45:29PM -0500, Amadeo Bellotti wrote:
> I was thinking it would be really nice if i could make a Pocket Linux distro
> that of course fits on one or two floppies (outdated I no but still are
> amazing) thats just the Linux kernel, bash, and python. with of course a lot
> of tiny scripts to do daily business and/or recovery. We could have a mail
> client, a text reader/editor, text based web browser, all in python. Of
> Course this will be a lot of work and it would be neat if the whole user
> group pitched in. so what I'm basically asking is that if you are interested
> email me and ill give you some detail.

What about the following?

http://www.rpath.org/rbuilder/project/lamp/
http://wiki.rpath.com/wiki/Appliance:LAMP_Appliance

Not a floppy.  But, I believe that you would be able to boot from a
CD.

LAMP is more than Python, but Python is an important part of it.

Dave


-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT What's next

2006-11-28 Thread Alan Gauld

"Amadeo Bellotti" <[EMAIL PROTECTED]> wrote

> I've recently wanted to learn more about my hardware and i figured 
> what
> better way then programming at the base level. I no it sounds stupid 
> but i
> would like to learn to manage my own memory. so i was wondering if 
> anyone
> has dipped there toe in either C or Assembly. If you have please 
> tell me
> which one you prefer and were a good site is

Never mind my toes getting wet, I was thrown in bodily! :-)

C is the way to go, although you may need to dip into assembler,
but that can be done most easily by using the 'inline' or 'asm' 
features
of most PC C compilers.

Pure assembler on a PC involves a huge amount of work for even
the most trivial task.

But for the Python programmer I'd consider Borland Delphi, based
on Pascal. Pascal is much more readable and Pythonic than C
and allows the same level of access to the underlying hardware
(and assembler when needed). OTOH Python is written in C so
learning C can help with understanding Python too!

HTH,

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why can't I import this?

2006-11-28 Thread Dick Moores
At 07:48 PM 11/28/2006, Kent Johnson wrote:
>Dick Moores wrote:
> > At 07:20 PM 11/28/2006, Kent Johnson wrote:
> >> Try
> >>from mine.toolTipDemo import demo
> >> mine.toolTipDemo points to the module, then you need to reference a name
> >> defined in the module. (You must have something called intSpell in
> >> intSpell.py.)
> >
> > Interestingly (or not) it just hit me that I should try that, and it
> > worked. So I suppose that if I want to use tooltips in a Tkinter
> > program, I can just use  "from mine.toolTipDemo import *" and use
> > what I need. (Haven't tried that yet, however.)
>
>Yes, you can do that but in general that style is not recommended. It
>makes it hard to figure out where names are defined and you can import
>more than you really want. Better is to just import what you want, e.g.
>from mine.toolTipDemo import A, b, CC

Thanks, Kent. Turns out all I needed was the class, ToolTip. So just

from mine.toolTipDemo import ToolTip

will do it.

>or import the module with an alias:
>import mine.toolTipDemo as TTD
>
>then refer to e.g.
>TTD.demo()

A good trick.

Thanks very much, Kent.

Dick



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Game programming - inventory management (was Help)

2006-11-28 Thread Luke Paireepinart
Bob Gailer wrote:
> Please use a meaningful subject line. Many of us try to follow 
> "threads", and "help" does not help.
> I have provided one for this case.
>
> Mohammed H. Hafeji wrote:
>   
>> Need some help in python.
>>  
>> How do i make the user choose wheter or not to pick it up? (i can do 
>> picking up an item from a list):
>> [snip bolded python code]
>> 
Please also don't format your code to look different from the rest of 
the e-mail.
I know what Python code looks like without seeing it bolded, italicized 
or colorized.
>>  
>> But i cant do when u have a choice to pick up or not.
>> 
It is helpful if you tell us what you have tried.
'I can't do x' doesn't help.
'I did x, but it didn't work out right.  I think x is working this way, 
but I meant for it to work that way.' would be very helpful.
>>  
>> Also if not too much trouble then how can i do:
>>  
>> IF the user picks the bat up then when he comes across the vampire 
>> then he kills it, but if he hasnt pickd up the bat then he dies?
>> 
What have you tried for this?
What do you think you might do?
>>  
>> Thanks in advance
>>  
>> P.S. Could u plz email sum code
>> 
We're not here to provide code for you.  It's a tutor list, meant to 
help you learn Python.
Giving you the code you want is most likely not going to help you nearly 
as much as if you had to make it yourself.

>> 
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>   
>> 
>
>
>   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor