importing classes from a variable

JustinHJ justinhj at hotmail.com
Thu Jan 18 19:02:41 EST 2001


Could anyone offer any advice on the following problem. What I have is a
python program that takes a file and does something to it by calling member
functions in a class. To seperate the code that does the export from the
main program, what I wanted to do is to be able to go from a text string
name of the export process....

str = 'export_1'

and do the equivalent of

import 'export_1'

exportclass = export1.Export.DoExport

So in case that's not clear I want to be able to import modules in a class
without knowing their name until runtime, then use the module name as a
variable.EG:

export_string = 'export_1'

import export_string # this doesn't work

export_string.Export # this doesn't work either







More information about the Python-list mailing list