Movatterモバイル変換


[0]ホーム

URL:


how to import from variable source

Brian Quinlanbrian at sweetapp.com
Sun Apr 15 04:11:45 EDT 2001


There is probably a better strategy but it is hard to guess what that wouldbe based on the information given.That said, there is a built-in function named "__import__" that does whatyou want:>>> print __import__.__doc____import__(name, globals, locals, fromlist) -> moduleImport a module.  The globals are only used to determine the context;they are not modified.  The locals are currently unused.  The fromlistshould be a list of names to emulate ``from name import ...'', or anempty list to emulate ``import name''.When importing a module from a package, note that __import__('A.B', ...)returns package A when fromlist is empty, but its submodule B whenfromlist is not empty.-----Original Message-----From:python-list-admin at python.org[mailto:python-list-admin at python.org]On Behalf Of Rob Brown-BaylissSent: Saturday, April 14, 2001 12:35 PMTo:python-list at python.orgCc:python-list at python.orgSubject: how to import from variable sourceHelloI am building a shell type app that imports modules depending on theusers actions.I do not want to have the import routines hard coded, rather I wouldlike to import from a variable like so:module = 'mymod'import moduleOnly, as I found out I get an error stating that there is not modulecalled module.Is this possible in python?  Is there a better way perhapse?Thanks,--  Rob Brown-Bayliss ---======o======---  www.ZOOstation.cc--http://mail.python.org/mailman/listinfo/python-list


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp