I'm currently working on a project that involve importing selected modules (https://github.com/yeyeto2788/MicroPythonScripts) that are already in the filesystem.
So let's say I have my script call `menu.py` and it will get all files on the filesystem and if I select one of them I want that module to be executed.
Files in the filesystem:
- menu.py
- boot.py
- test.py
- abs.py
Code: Select all
import time, os
def get_files():
extensions = ".py"
excluded_files = ["main.py", "boot.py"]
dirfiles = []
for filename in os.listdir():
if filename.lower().endswith(extensions):
if filename.lower() not in excluded_files:
dirfiles.append(filename.replace(extensions, ""))
return dirfiles
a = get_files()[1]
import a
a.show()
Code: Select all
print("wujuuuu imported!")
I get an error saying the following:
Code: Select all
b'Traceback (most recent call last):\r\n File "<stdin>", line 12, in <module>\r\nImportError: no module named \'a\'\r\n')