I am working on a project eiler and would like to type all my code. I have a file directory in the form of "problemxxx.py", where xxx is the problem number. Each of these files has a function main()that returns a response. So I created a file called run.py located in the same directory as the problem files. I can get the file name on the command line. But when I try to import the problem file, I keep getting ImportError: No module named problem. Below is the code for run.py so far along with the command line used.
import sys
problem = sys.argv[1]
import problem
problem.main()
The command line queries I tried are the following: (both of them provide the ImportError value above)
python run.py problem001
python run.py problem001.py
How can I import a function main()from problem001.py file? Is an import imported with the file name stored in the variable? Is there a better solution than trying to get the file name through the command line? Let me know if I need to add more information, and thanks for any help!
source
share