Hello there I would like some to address me properlly on how to use importlib.import_module
I am attempting to import a module using the lib: but what I am getting is:
this is the example of my class:
class Main:
def __init__:
self.appFileName=None
self.appFileToPass=None
def decrypt(self, string):
return cryptocode.decrypt(string, localKey)
def decrypFile(self, file):
# decrpts the file
newFile=""
with open(file) as f:
line = f.readline()
while line:
line = f.readline()
newFile+=str(self.decrypt(line))
# creats a random name
alphaName=f"{''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase) for _ in range(random.randint(9,12)))}"
self.appFileName=f"{alphaName}.py"
self.appFileToPass=alphaName
# save file locally
with open(self.appFileName, 'w') as myprints:
myprints.write(newFile)
myprints.close()
def run(self):
self.decrypFile("fileToDecrypt")
app=importlib.import_module(self.appFileName)
if __name__ == "__main__":
main=Main()
main.run()
the error :
Exception ignored in thread started by: <bound method runApp of <__main__.my class>
Traceback (most recent call last):
File "C:\Myfile.py", line 4747, in runApp
app=importlib.import_module(self.appFileName))
File "C:Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'appR'