+ 1
Function that imports modules
Hello, community! I wanted to write a program (Python) that includes a function with a module name as an argument. So if the user inputs a module name, the function would import it. I tried it, but the argument of that function is not assigned to the method name of the 'import <method name>' line. I hope it's kinda clear what I mean :) I wish you all a nice weekend!
2 Respostas
+ 4
i am not sure that is possible and why would you do that, function is not using for import modules
+ 1
You can do it, but you need to use the __import__() function instead of use the import statement:
http://python-reference.readthedocs.io/en/latest/docs/functions/__import__.html