newbie - How do I import automatically?

Claudio Grondi claudio.grondi at freenet.de
Thu Nov 17 05:22:18 EST 2005


"Mikael Olofsson" <mikael at isy.liu.se> schrieb im Newsbeitrag
news:dlhcch$gud$1 at news.island.liu.se...
> bobueland at yahoo.com wrote:
> > I tried to put the line
> > from btools import *
> > in several places in PyShell.py
> > but to now avail. It does not work, IDLE does not execute it???
>
> IDLE definitely executes PyShell.py upon startup, since IDLE does not
> even appear on the screen if there is an error in that file. The
> following seems to work for me, in PyShell.py. After importing both sys
> and os,
>
> sys.modules['__main__'].__dict__['os'] = os
>
> Then, if I start IDLE, the module os is directly available.
>
> HTH
> /MiO


I have put
sys.modules['__main__'].__dict__['os'] = os
at the beginning of PyShell.py :
"
#! /usr/bin/env python

import os
import os.path
import sys

sys.modules['__main__'].__dict__['os'] = os
"

and also here:
"
class ModifiedInterpreter(InteractiveInterpreter):

    def __init__(self, tkconsole):
        self.tkconsole = tkconsole

        sys.modules['__main__'].__dict__['os'] = os
        locals = sys.modules['__main__'].__dict__
"

but it does not work ... (why ???)

What happens if you remove the line
sys.modules['__main__'].__dict__['os'] = os
from your PyShell.py?
Will  os  be no more available or is it still there?

Claudio






More information about the Python-list mailing list