A
Alexander Myodov
Hello,
Having heard that Python 2.5 offers some kind of RIIA concept via
PEP343, got it downloaded (Windows version) and tried. But it did not
work as expected and as wanted.
For the time since I first learned Python, the only reason why I just
could not use it was inability to localize the lifetime of some
variables inside some syntactical "blocks", especially ones in
"for"/"while"/"if" statements, but possibly in any "manually
generated" block (say, like if I would create a "{}" block in C/C++
just to separate one part of the function from another). I mean the
cases like
for k in a1:
pass
print "k: %s" % k
where "k" lives long after the actual need in it was lost, and even
list comprehensions:
b1 = [l for l in a1]
print "l: %s" % l
..
So, with 2.5, I tried to utilize "with...as" construct for this, but
unsuccessfully:
from __future__ import with_statement
with 5 as k:
pass
print k
- told me that "AttributeError: 'int' object has no attribute
'__context__'".
So, does this mean that we still don't have any kind of RIIA in
Python, any capability to localize the lifetime of variables on a
level less than a function, and this is indeed not gonna happen to
change yet?
Having heard that Python 2.5 offers some kind of RIIA concept via
PEP343, got it downloaded (Windows version) and tried. But it did not
work as expected and as wanted.
For the time since I first learned Python, the only reason why I just
could not use it was inability to localize the lifetime of some
variables inside some syntactical "blocks", especially ones in
"for"/"while"/"if" statements, but possibly in any "manually
generated" block (say, like if I would create a "{}" block in C/C++
just to separate one part of the function from another). I mean the
cases like
for k in a1:
pass
print "k: %s" % k
where "k" lives long after the actual need in it was lost, and even
list comprehensions:
b1 = [l for l in a1]
print "l: %s" % l
..
So, with 2.5, I tried to utilize "with...as" construct for this, but
unsuccessfully:
from __future__ import with_statement
with 5 as k:
pass
print k
- told me that "AttributeError: 'int' object has no attribute
'__context__'".
So, does this mean that we still don't have any kind of RIIA in
Python, any capability to localize the lifetime of variables on a
level less than a function, and this is indeed not gonna happen to
change yet?