Re: Dyanmic import of a class

2007-03-22 Thread Facundo Batista
rh0dium wrote: > foo.py > > class foo: >def __init__(self): > print "Hi I am %s" % self.__class__.__name__ I wrote this in a file here... > Now I have a bunch of these files. I want to be able to dynamically > import each one and run it. I am having a problem actually doing the > wo

Re: Dyanmic import of a class

2007-03-08 Thread Scott David Daniels
Arnaud Delobelle wrote: > On Mar 8, 9:09 pm, "rh0dium" <[EMAIL PROTECTED]> wrote: > [snip] >> for mod in listdir(): >>__import__(mod) >>a=mod() >>a.dosomething() # This is a function which each class shares. >> >> Can anyone help? > > You are not using __import__ correctly. Perhap

Re: Dyanmic import of a class

2007-03-08 Thread Arnaud Delobelle
On Mar 8, 9:09 pm, "rh0dium" <[EMAIL PROTECTED]> wrote: [snip] > for mod in listdir(): >__import__(mod) >a=mod() >a.dosomething() # This is a function which each class shares. > > Can anyone help? You are not using __import__ correctly. Perhaps reading the doc would be a good start:

Dyanmic import of a class

2007-03-08 Thread rh0dium
Hi all, I have a directory with a bunch of python classes each uniquely named such that the file name (dropping .py) is also the class name of the file in question. So for example foo.py class foo: def __init__(self): print "Hi I am %s" % self.__class__.__name__ Now I have a bunch of