Re: Cannot import a module from a variable

2006-10-18 Thread Fredrik Lundh
Cameron Walsh wrote: > Woah, that actually works? Having the "finally" after the "return"? > That could make some things easier, and some things harder... The whole point of having a clean-up handler is to make sure it runs no matter what: When a return, break or continue statement is exec

Re: Cannot import a module from a variable

2006-10-18 Thread Cameron Walsh
Gabriel Genellina wrote: > At Wednesday 18/10/2006 22:51, Cameron Walsh wrote: > >> previous_directory = os.getcwd() >> try: >> os.chdir(directory) >> [ ... ] >> return modules >> finally: >> os.chdir(previous_directory) >> >> Woah, that actually works?

Re: Cannot import a module from a variable

2006-10-18 Thread Gabriel Genellina
At Wednesday 18/10/2006 22:51, Cameron Walsh wrote: previous_directory = os.getcwd() try: os.chdir(directory) [ ... ] return modules finally: os.chdir(previous_directory) Woah, that actually works? Having the "finally" after the "return"? That could

Re: Cannot import a module from a variable

2006-10-18 Thread Cameron Walsh
Hi, This has actually been answered in a previous post ("user modules" started by myself), for which I was very grateful. I have since expanded on their solutions to create the following code, of which parts or all may be useful. You'll probably be most interested in the last part of the code, f

Re: Cannot import a module from a variable

2006-10-17 Thread Duncan Booth
"Tim Williams" <[EMAIL PROTECTED]> wrote: >> The import statement expects a name (a symbol), not a string. >> > > eval( 'import %s' % modname) > > and > > eval( 'reload(%s)' % modname) > > Usual warnings about eval apply, but in this case it is usable. Did you actually try your suggestion be

Re: Cannot import a module from a variable

2006-10-17 Thread Fredrik Lundh
Tim Williams wrote: > eval( 'reload(%s)' % modname) reload takes a module object, not a module name. since you need to have the object, you might as well pass it to the reload() function. -- http://mail.python.org/mailman/listinfo/python-list

Re: Cannot import a module from a variable

2006-10-17 Thread Tim Williams
On 16/10/06, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Jia Lu wrote: > > Hi all: > > > > I try to do things below: > import sys > for i in sys.modules.keys(): > > import i > > Traceback (most recent call last): > > File "", line 2, in > > import i > > ImportError: No m

Re: Cannot import a module from a variable

2006-10-16 Thread Bruno Desthuilliers
Jia Lu wrote: > Hi all: > > I try to do things below: import sys for i in sys.modules.keys(): > import i > Traceback (most recent call last): > File "", line 2, in > import i > ImportError: No module named i > > But it seems that import donot know what is i ? The import s

Re: Cannot import a module from a variable

2006-10-15 Thread Colin J. Williams
Christian Joergensen wrote: > "Jia Lu" <[EMAIL PROTECTED]> writes: > >> Hi all: >> >> I try to do things below: > import sys > for i in sys.modules.keys(): >> import i >> Traceback (most recent call last): >> File "", line 2, in >> import i >> ImportError: No module named i >>

Re: Cannot import a module from a variable

2006-10-15 Thread Christian Joergensen
"Jia Lu" <[EMAIL PROTECTED]> writes: > Hi all: > > I try to do things below: import sys for i in sys.modules.keys(): > import i > Traceback (most recent call last): > File "", line 2, in > import i > ImportError: No module named i > > But it seems that import donot know what

Cannot import a module from a variable

2006-10-15 Thread Jia Lu
Hi all: I try to do things below: >>>import sys >>> for i in sys.modules.keys(): import i Traceback (most recent call last): File "", line 2, in import i ImportError: No module named i But it seems that import donot know what is i ? why? Thanks/ -- http://mail.python.org/mailman