[Tutor] eval and exec

Alan Gauld alan.gauld at freenet.co.uk
Sun Dec 5 10:05:19 CET 2004


> I was trying to eval("import %s" % something).
>
> exec("import %s" % something) works just fine and now I understand
why.

But much better to use the __import__() function for doing that
if possible... Or simply importing all the modules you might need
at the beginning, its not a big overhead...

Alan G.



More information about the Tutor mailing list