A little disappointed so far
Terry Reedy
tjreedy at udel.edu
Mon May 19 17:30:48 EDT 2003
"Joshua Marshall" <joshway_without_spam at mathworks.com> wrote in
message news:baatpl$k3f$1 at ginger.mathworks.com...
> This doesn't matter - "++" dosen't need to affect the integer
object.
> It could be defined so that:
> >>> x = 1
> >>> y = x++
> >>> x
> 2
> >>> y
> 1
Syntactically, it would be definitately 'unPythoninc' for a operator
to have such a side-effect. But if wanted badly enough....
def pi(gvname): # post increment global variable
g = globals()
t = g[gvname]
g[gvname] = t+1
return t
x = 1
y=pi('x')
print x, y
# prints 2 1
but this only works for code at module level. (For generality, a
*lot* more would be needed to get the calling frame, decide if modular
or functional, and if the latter, fiddle with the function's local
vars -- though I believe it might be possible based on what people
have posted at various times ;-)
> But I don't think it's a good idea. I personally dislike this
feature of C.
Good. It would never make it into Python.
Terry J. Reedy
More information about the Python-list
mailing list