0
I tried with the module inspect
but I couldn’t get the result.
The concept is: "scan" a file through a decorator
.
Stages
- Capture variable
file
before functionread_file
be called - "Scan" filing cabinet
- Return or not the function that called the
decorator
I have tried in many ways and agree that I have found no way to do this, even using the module inspect
from the Standard Python library.
def scan_files(funcs):
print(funcs.__code__.co_varnames)
return funcs
@scan_files
def read_file():
file = open('arquivo.txt', 'w')
file.close()
with open('arquivo.txt', 'w') as new_file: ...
PS: for reasons of readability omit some factors, such as, functions with named arguments or not, variable not having the fixed name being necessary to know the type taken as Object file.
That’s not exactly what I thought I’d develop. The function I set up in read_file itself, was just an example, but I thought of something bigger as, a function with manipulation with many files. However, you made me think of a number of things, such as readability, usability, maintenance, and omission/error generation that will surely happen. In a way you helped me indirectly, so I just have to thank you. Thank you!
– Franklin Timóteo