Aug-22-2022, 06:55 PM
Complaining that text is not defined is a valid complaint. There is no variable named "text" defined in ma() or in the global scope. There is a variable named "text" defined in run(), but that variable, like all local variables in a function, is not visible outside run().
Looking at you initial code, ma() used "data" and "vet". You got data by doing this:
And you got vet by doing this:
Looking at you initial code, ma() used "data" and "vet". You got data by doing this:
text = docx2txt.process(files[i]) text2 = text.replace(":", " ") text3 = text2.replace(",", " ") text4 = text3.replace("_", " ") data = text4.split()which is the same as:
text = docx2txt.process(f).replace(":", " ").replace(",", " ").replace("_", " ")data = text.split()
And you got vet by doing this:
vet = "" for j in data: vet += j + ", "which is the same as this:
", ".join(text.split())Since ma() needs both data and vet, and vet is easily created from data, I think it makes more sense to pass data to ma() and have ma() create vet.
def ma(data): vet = ", ".join(data) ... def run(): for f in os.listdir(path): if f.endswith('.docx'): text = docx2txt.process(f).replace(":", " ").replace(",", " ").replace("_", " ") ma(text.split()) # This creates data from text and passes it to ma print('Transfert de donnée Réussi!')