how to import from variable source

Martin Bless m.bless at gmx.de
Sun Apr 15 09:00:25 EDT 2001


>Use the __import__() builtin function:
>
>	module = __import__('mymod')

Is there a way to manipulate the resulting 'mymod.__name__'?

If - against normal behavior - it could be set to '__main__' the
imported 'mymod' could be deceived leading to execution of code
in the common common
if __name__ == '__main__': pass  # do something
clause.

Martin




More information about the Python-list mailing list