[Edu-sig] Code Examples using IDLE
Kirby Urner
pdx4d@teleport.com
Fri, 29 Sep 2000 09:47:35 -0700
Greetings Fredrik --
No need to respond to this; I know you're super-busy.
Just wanted to mention that we IDLE users like to tweak and
reload modules quite a bit, including your Standard Library
examples.
You show how using __import__ directly gets around the fact
you use hyphens in your module file names. However, your
reload(hello) example doesn't show how to reload with hyphenated
modules -- which for IDLE users is the easiest way to force
re-evaluation of tweaked code.
So for example when I first __import__("socket-example-1"),
it executes and gives a server time. If I open this module in
IDLE and change the server name, then I'd like to reload
and have it execute a second time. I floundered around for
awhile and then came up with a way to do it.
My solution is to go:
>>> v = __import__("socket-example-1")
host is: www.python.org
server time is Fri Sep 29 09:27:39 2000
local clock is 4 seconds off
[change host in source code -- module open in window]
>>> reload(v)
host is: clock.sgi.com
server time is Fri Sep 29 09:41:57 2000
local clock is 2 seconds off
<module 'socket-example-1' from 'G:\PYTHON20\lundh\socket-example-1.py'>
[change host in source code -- module open in window]
>>> reload(v)
host is: ntp-cup.external.hp.com
server time is Fri Sep 29 09:43:08 2000
local clock is 2 seconds off
<module 'socket-example-1' from 'G:\PYTHON20\lundh\socket-example-1.py'>
I'm using some of the public access time servers listed on:
http://www.eecis.udel.edu/~mills/ntp/clock1.htm
Perhaps in some future draft of your excellent book, you could
throw in a few words for the "IDLE community" (that makes it
sound like we're lazy, which I guess in some sense is true).
Kirby
PS: I notice www.pythonlabs.com is not as friendly to testers:
>>> reload(v)
Traceback (innermost last):
File "<pyshell#2>", line 1, in ?
reload(v)
File "G:\PYTHON20\lundh\socket-example-1.py", line 13, in ?
s.connect((HOST, PORT))
File "<string>", line 1, in connect
error: (10060, 'Operation timed out')
Won't even give me the time of day :-(
PPS: thanks again for sending source code examples. I'm anticipating
hours of fun and games.