I am writing a text-based Madlibs game in Python, but it has code separated into multiple scripts to make development easier.
I have already tried importing the required files using a for loop:
import os, importlib
foundStories = os.listdir('...madlibs/stories')
for story in foundStories:
importlib.import_module(story)
I had to use importlib because the built-in import import apparently doesn't support passing in module names as a variable.
Every time I run the script I get these errors:
Traceback (most recent call last):
File "Madlibs-v7-TEST.py", line 7, in <module>
importlib.import_module(story)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'story3'
Should also mention that my 'story files' are just ordinary Python scripts themselves, they are not 'Python modules' or anything.
Please try to keep answers simple and legible, as I am a beginner programmer.
I only program as a hobby, and have no interest in software development.
I'm guessing this has to do with a problem in my Python build and not my code at all.
For reference, my OS is: Ubuntu 20.04