Hendrik van Rooyen wrote: > Hi there, > > I can write: > > s = 'some string' > then print s[1] will be the string 'o' > > and a while later I can write: > > s = 'other some string' > then print s[1] will be the string 't' > > and then: > > s = [1,2,3,4] > then print s[1] will be the number 2 > > and still later: > > s = {1:'boo',2:'foo',3:'shoo'} > when print s[1] will yield the string 'boo' > > Now how about introducing an index that works over time, > such that s{0} (the default so as to not break any existing code) > implies the current object bound to the name s, > with s{1} being the previous one, and so on... > > This will mean that s{2}[1] is the string 't' > and s{3}[1] is the string 'o' > while s{4} should be None... > > It should be easy to implement this, as all that needs to be done is to > change the "pointer" (or whatever) to the object with a stack of them > at the time the binding or rebinding is done... > > I first thought of using s{-1} for the previous "value" but that > suffers from the regrettable disadvantage that it implies the > existence of an s{1} - i.e. a future value - and I could not think > of a way to achieve this - so the minus sign adds no information > and should therefore be left out... > > What do you guys think?
I think it's pointless. If you want access to more than one of these variables, don't use the same name. That and if a symbol is still in scope, then all of its previous values still have active references, so they won't get deallocated by the garbage collector, meaning a lot of overhead that most people will not take advantage of. -- http://mail.python.org/mailman/listinfo/python-list