I have a string coming from the database. This string is the name of a file .py that is within a module. The structure is this:
files
├── file1.py
├── file2.py
└── __init__.py
The file1.py
contain:
def file1(imprime):
print(imprime)
The file2.py
contain:
def file2(imprime):
print(imprime)
I need to convert the string to a function that can be callable.
In main.py
file I try:
import files
string = "file1.py"
b = getattr(file1, string)
text = 'print this...'
b(text)
Can anyone help me?