[Tutor] Learning Python with a Simple IM
alan.gauld at freenet.co.uk
Sun Jul 10 16:56:39 CEST 2005
> I am a Java Developer that wants to learn Python by doing.
> I am loving this initial vibe I'm getting out of Python.
> However, because I feel programmers of a certain languages
> bring with them certain vices when moving to other languages,
Absolutely right, thats why its good to learn several languages
- to see the world from different angles! ;-)
> print "Please enter the following information"
> _url = raw_input("URL: ")
Using an underscore in front of a variable is usually done in a class
make the member "invisible" - a wee bit like private in Java, but
much less rigorous. Its not often used for normal variables in a
> print '\n'
> print "Connecting to server..."
> print '\n'
Using a tripple quioted string might be easier here:
Connecting to seerver
> while 1:
> response = socketOut.recv(8192)
> if response != " ":
> print "\n" + response
There is no break in this loop so it will run forever.
That might be what you want, but usually I'd put some kind of
breakout mechanism even on a long running server daemon.
> if msvcrt.kbhit():
> ch = msvcrt.getche()
I may be wrong but I don;t think you need the kbhit() function,
getch[e]() will block and wait for a keypress.
> ch = None
Which in turn means ch should never be None...
Although it might never exist if kbhit is not True since getche
will never be called and thus ch will never be created!
(Recovering from G8 riots 300m from his house!)
More information about the Tutor