newbie - How do I import automatically?

Mikael Olofsson mikael at isy.liu.se
Thu Nov 17 04:52:58 EST 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?

Yes, I do. The following is with IDLE 1.0.3 and Python 2.3.4 on WinXP.

Without the line in PyShell.py:

     IDLE 1.0.3      ==== No Subprocess ====
     >>> dir()
     ['__builtins__', '__doc__', '__file__', '__name__', 'main']

With the line in PyShell.py:

     IDLE 1.0.3      ==== No Subprocess ====
     >>> dir()
     ['__builtins__', '__doc__', '__file__', '__name__', 'main', 'os']
     >>> os
     <module 'os' from 'C:\Python23\lib\os.pyc'>

I know nothing about the details of how IDLE work. All I know is what I 
have reported here. I was simply inspired by the following remark from 
Claudio Grondi up-thread:

 > edit the first lines of %SystemDrive%\Python24\Lib\idlelib\PyShell.py

I guess that PyShell.py is imported as a module by IDLE at startup.

One thought, though: Du you have more than one Python installed? If so: 
Could it be that you are editing the wrong PyShell.py?

Regards
/MiO



More information about the Python-list mailing list