[Python-ideas] For-loop variable scope: simultaneous possession and ingestion of cake

Carl Johnson carl at carlsensei.com
Mon Oct 6 04:56:04 CEST 2008

Oh, I thought of something. What if you try to immanentize a variable  
in function that only exists in the function's scope? I think that  
should cause an error to be raised.

So, this should work:

 >>> j = 5
 >>> def f():
...     immanentize print(j)

But this should not:

 >>> def f():
...     j = 5
...     immanentize print(j)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in f
ImmanentizingNameError: name 'j' is not defined in the current scope

-- Carl

More information about the Python-ideas mailing list