newbie - How do I import automatically?

Mikael Olofsson mikael at isy.liu.se
Thu Nov 17 11:29:21 CET 2005


bobueland at yahoo.com wrote:
>> I tried to do it on my computer (win XP). I put an extra line in
>> PyShell.py
>> [snip]
>> # test
>> sys.modules['__main__'].__dict__['os'] = os
>> [snip]
>> Then when I start idle I get
>>
>> IDLE 1.1.1
>>
>>>>> dir()
>>
>>
>> ['__builtins__', '__doc__', '__name__']
>>
>>
>> So I don't see 'os'
>>
>> Do you see 'os' on your computer. If yes, what could be the difference?
> 
> 

I answered:
> Yes, I do. [snip details]

I have to step back a bit. IDLE seems to work differently depending on 
how it is started. My comments above hold when I start IDLE by 
right-clicking on a python-file and choosing "Edit with IDLE".

If I instead start IDLE itself (from the windows start-menu) I get the 
same behaviour as you do, namely no os around. Another difference, which 
I've noted before is that shell restart is only available when IDLE has 
been started this way.

All this seems to be handled in PyShell.py, but I do not have the time 
to trace that in any detail.

Regards
/MiO



More information about the Python-list mailing list