2 ms·
Some years ago I wrote a Python function, "replace_me"[1], that edits the caller's source code. You can use it for code generation, inserting comments, generati
by BoppreH 4y ago
Some years ago I wrote a Python function, "replace_me"[1], that edits the caller's source code. You can use it for code generation, inserting comments, generating fixed random seeds, etc.
And one more use case I found was exactly what TFA describes, but even easier:
import replace_me
replace_me.test(1+1)
Once executed, it evaluates the argument and becomes an assertion:
import replace_me
replace_me.test(1+1, 2)
I never actually used it for anything important, but it comes back to my mind once in a while.
[1]: https://github.com/boppreh/replace_me https://github.com/boppreh/replace_me