[Tutor] Getting import to use a variable name

Jim Mooney Py3.4.3winXP cybervigilante at gmail.com
Wed May 20 02:25:30 CEST 2015


On 19 May 2015 at 17:18, Ben Finney <ben+python at benfinney.id.au> wrote:

> You will be pleased to know of the standard library ‘importlib’
> library::
>
>     >>> import importlib
>

Yes, I already got importlib to accept a string. But I can't figure how to
get dir to accept it:

>>> x = 'shutil'
>>> import importlib
>>> importlib.__import__(x)
<module 'shutil' from 'C:\\Python34\\lib\\shutil.py'>
>>>

If I can get dir to accept x I can parse the output to get rid of the __xxx
stuff and print it out.


-- 
Jim

After not doing dishes for a week and washing spoon after spoon, fork after
fork, knife after knife - I suddenly understand the mathematical concept of
infinity, which is just one more damn thing after another.


More information about the Tutor mailing list