Jan-04-2023, 03:13 AM
def funa(): print('started funa') foo = 'bar' def funb(): print('started funb') print('locals() =',repr(locals())) print('locals() has "foo":','foo' in locals()) print('end funb') def func(): print('started func') print('locals() =',repr(locals())) print('locals() has "foo":','foo' in locals()) print('foo =',repr(foo)) print('locals() =',repr(locals())) print('locals() has "foo":','foo' in locals()) print('end func') return funb() func() print('end funa') return funa()then when i run it i get:
Output:started funa
started funb
locals() = {}
locals() has "foo": False
end funb
started func
locals() = {'foo': 'bar'}
locals() has "foo": True
foo = 'bar'
locals() = {'foo': 'bar'}
locals() has "foo": True
end func
end funa
when funb() or func() is called, they may or may not access the callers locals. this seems to depend on the compiler seeing it or something. this could break accessing locals()[name]
where name refers to "foo". i think i need to play with it more to see what it really does.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.