Is there a way importing a string object?
Ben Finney
ben+python at benfinney.id.au
Mon Jan 4 19:59:51 EST 2016
jfong at ms4.hinet.net writes:
> For example,
(Please make the body of your message complete. The “Subject” field
should be a summary of your message's subject, and may not be read as
the first line of your message.)
> name = "test" # test.py is a module's file
> import name
The standard library ‘importlib’ module exports an API for the import
machinery <URL:https://docs.python.org/3/library/importlib.html>.
You will likely want to use ‘importlib.import_module’
<URL:https://docs.python.org/3/library/importlib.html#importlib.import_module>.
--
\ “The difference between a moral man and a man of honor is that |
`\ the latter regrets a discreditable act, even when it has worked |
_o__) and he has not been caught.” —Henry L. Mencken |
Ben Finney
More information about the Python-list
mailing list