demo_ref_locals2.py:
x = locals() print(x["__file__"])
➜ begtut>python demo_locals2.py
demo_ref_globals2.py