To find a module’s path, I would like to use the following script:
import <module_name>
print <module_name>.__file__
It works.
However, I want to make it more flexible, to receive an argument to specify the module’s name.
If I name the script as searchModulePath.py, I want to run it with searchModulePath.py <some_module_name>.
Here is what I have tried:
#!usr/bin/python
import sys
print sys.argv
import sys.argv[1]
print sys.argv[1].__file__
But it doesn’t work:
File "searchModulePath.py", line 5
import sys.argv[1]
^
SyntaxError: invalid syntax
And, the print statement in the 2nd line doesn’t print out anything, 🙁
Anything I missed here?
You can’t use variables in import statements, you should use the builtin
__import__in stead: