tags:

views:

34

answers:

1

Idlestartup is analogous to pythonstartup variable, but for IDLE, instead of command line. But it seems not to work properly. I'm using python 2.6.5 on Windows.

I have the following script assigned to it:

from pprint import pprint
import sys
newPath = 'C:\\Python26\test')
sys.path.append(newPath)
print "initial config loaded"

Both variables Idlestartup and pythonstartup are assigned to the same file (script above). When running IDLE, pprint and sys are NOT available, the final message is NOT printed, but newPath was added to sys.path. Running the command line, pprint and sys are available, the final message is printed and newPath was added to sys.path.

Is it a bug? Am I doing something wrong? Thanks

+3  A: 

sys.stdout may not be in its final state at the time idlestartup's getting loaded - so it's quite possible that a print to it tries to go to the "original" standard-output, and then immediately the standard output is redirected to idle's command window and so the effects of the print are never seen. In other words, no bugs, I think -- it's just not obvious how idlestartup may be guaranteed to send an important message to the user, if delivery of that message must be guaranteed (a message such as your example is no big deal, but if you did have important ones I'd look into Tk ways of delivering them in a guaranteed way).

Edit: as for making sure that certain names are added to the main namespace, the latter's named __main__ (both with and without idle), so adding to your code a few statements such as

sys.modules['__main__'].pprint = pprint

&c should work.

Alex Martelli
Thanks for your explanation. I don't care about the message, but I would want pprint and sys (and other modules that I may include later) to be always available. Any idea on how to get around of this issue? I have tried customize.py as well, but it worked the same way.
duduklein
@user, OK, edited my answer to clarify that part.
Alex Martelli
I added the line you suggested at the end of my file and it did not work. Any other ideas? Thanks
duduklein