View Single Post
Old Aug 14th, 2006, 3:11 PM   #6
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Quote:
Originally Posted by titaniumdecoy
Yes, but why doesn't curr behave like a static variable when it is not a list?
Because in your case the variable would be immutable, simply an integer.
To follow this up with an example:
# Python's version of a static variable
def static_num(list1=[0]):
    """The function's default is a list with one element = zero.
    Since the list is a mutable object it retains its address,
    as the function's default is created at compile time.
    Whatever you put into this list as element is retained too"""
    list1[0] += 1
    return list1[0]

print static_num()  # 1
print static_num()  # 2
print static_num()  # 3 
...
Well, not quite the same beast! Maybe Sane can help!
__________________
I looked it up on the Intergnats!

Last edited by Dietrich; Aug 14th, 2006 at 3:38 PM.
Dietrich is offline   Reply With Quote