Interesting Problem

M.-A. Lemburg mal at
Wed Jan 20 20:11:55 CET 2010

Victor Subervi wrote:
> Hi;
> I think I finally have an interesting problem for y'all. I need to import a
> script from a lower dir, forcing me to change dirs:
> cwd = os.getcwd()
> os.chdir('%s/..' % cwd)
> sys.path.append(os.getcwd())
> from templateFrame import top, bottom
> os.chdir(cwd)

I suggest you read up on the built-in __import__() function:

There's no need to change sys.path just to import a module.

If you only need to execute some Python from a file, use execfile():

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Jan 20 2010)
>>> Python/Zope Consulting and Support ...
>>> mxODBC.Zope.Database.Adapter ...   
>>> mxODBC, mxDateTime, mxTextTools ...

::: Try our new mxODBC.Connect Python Database Interface for free ! :::: Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611

More information about the Python-list mailing list