Re: Tricky import question.

2005-10-25 Thread David Poundall
repr() is a new one on me I am afraid, and I have yet to achieve any decent competance with global and local lists. As you probaly noticed earlier, I managed to bungle my way through this time. However, I will log this thread away for when I next get stuck with a bindings. Thank you Bengt :-)

Re: Tricky import question.

2005-10-25 Thread David Poundall
All I was trying to do with my feeble code attempt, was to return a reference to the imported module so that I could do... result = instanceref.main() where main was a function within the import. Having glanced at the code in the import section of the help files all morning, when I actually sat

Re: Tricky import question.

2005-10-25 Thread Bengt Richter
On 25 Oct 2005 08:51:08 -0700, "David Poundall" <[EMAIL PROTECTED]> wrote: >This worked ... > >def my_import(name): >mod = __import__(name) >components = name.split('.') >for comp in components[1:]: >mod = getattr(mod, comp) >return mod > >for reasons given here... > >http:

Re: Tricky import question.

2005-10-25 Thread Bengt Richter
On 25 Oct 2005 06:39:15 -0700, "David Poundall" <[EMAIL PROTECTED]> wrote: >importedfiles = {} >for f in FileList > f2 = f.split('.')[0] # strip the .py, .pyc importedfiles[f2] = __import__(f2).main # it sounds like all you want is the above (untested ;-), or # use __import__(f2).m

Re: Tricky import question.

2005-10-25 Thread David Poundall
This worked ... def my_import(name): mod = __import__(name) components = name.split('.') for comp in components[1:]: mod = getattr(mod, comp) return mod for reasons given here... http://www.python.org/doc/2.3.5/lib/built-in-funcs.html -- http://mail.python.org/mailman/l

Re: Tricky import question.

2005-10-25 Thread David Poundall
Sadly I get this reply when I try that. AttributeError: 'module' object has no attribute 'main' I am getting the impression that the value returned from the __import__() function is only a string reference NOT an object. I am going to have a go at trying this with the imp' module as that specifi

Re: Tricky import question.

2005-10-25 Thread Fredrik Lundh
David Poundall wrote: > importedfiles = {} > for f in FileList > f2 = f.split('.')[0] # strip the .py, .pyc > __import__(f2) > s2 = f2+'.main()' # main is the top file in each import > c = compile(s2, '', 'eval') > importedfiles[f2] = eval(c) > > 'importedfiles' should hold an