How to instatiate a class of which the name is only known at runtime?

Marco Herrn herrn at gmx.net
Tue Sep 9 21:35:30 CEST 2003


Hi,

I am writing a program that has to instantiate a class from which I
don't know the name until runtime. That leads to two problems for me.

1. How to do the import? I didn't find a way to give a string to the
   import statement.

2. How to write such code to instantiate?

The first is a problem, when I don't know where the classes reside.
Currently it is planned that all these classes reside in a specific
subdirectory. Is it possible to say 'import * from subdirectory' ?
What other problems could occur here and how could I avoid them?

And to the second question, I have no idea about how to do this. Any
hints?


Bye
Marco

-- 
You can't judge a book by the way it wears its hair.

--
Marco Herrn             herrn at gmx.net
(GnuPG/PGP-signed and crypted mail preferred)
Key ID: 0x94620736





More information about the Python-list mailing list