my_var = 3
assert('my_var' in locals())
import a_module
assert('a_module' in locals())
from sys import *
assert('stdin' in locals())
I also think you can inject with calls to locals() and globals()?
Anyway, I love python because it’s so explicit with imports. If a name is used, you can usually trace back to exactly where that name was defined. But, I’ve recently been running into modules wherein I want to find where the name qux is defined. The module itself contains no from something import *, no locals or globals, but when I CTRL+F for that name I find it only on the RHS of expressions, nowhere defined!
So my question is this: what are all the mechanisms by which a name can enter the local namespace? Can normal imports inject into my local namespace?
Some other module may inject the name in this module:
And this module does not define it:
Another crazy way someone may inject code in another module would be:
So,
a.pywill inject the namelolin whoever import it