5

I want to allow the user to import a module based on their string input argument.

i.e

$python myprogram.py --import_option xyz.py

In python I want something like this after parsing an argument.

arg = 'xyz.py'

import arg #assuming that the module name xyz.py exists.
0

1 Answer 1

12
>>> a='math'
>>> import importlib
>>> i=importlib.import_module(a)
>>> i.sqrt(4)
2.0
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.