0

Im sorry I know this is really stupid question, but I'm having a hard time passing a variable through simple python commands. I'm coming from BASH so I would simply use $ to solve this.

module = input("Enter module name: ")

import module
content = dir(module)
print (content)


exit (0)

How do I let python know "module" is a variable here?

1 Answer 1

1

You could use a python library called importlib to do such a task

The sample code is given below

import importlib
module_name = input("Enter the module to be imported: ")
imported_module = importlib.import_module(module_name)

print(imported_module.getcwd())

Here I was importing the os library for demonstrating how the imported library would work and print it's output directly

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.