I have tried the following:
>> modname = 'sys'
>> import modname
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named modname
Why does import not recognize 'sys' as the name of the module to be imported?
use importlib module if you want to import a module based on a string.
>>> import importlib
>>> mod = importlib.import_module('sys')
>>> mod
<module 'sys' (built-in)>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With