Interesting Problem

M.-A. Lemburg mal at egenix.com
Wed Jan 20 14:11:55 EST 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:

	http://docs.python.org/library/functions.html#__import__

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():

	http://docs.python.org/library/functions.html#execfile

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jan 20 2010)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


   eGenix.com 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
               http://www.egenix.com/company/contact/



More information about the Python-list mailing list