Monday, February 8, 2016

Python Static variables


#static vars are not directly posible in python
# for eg to count no. of times a func is called
def myFunc():
myFunc.count =getattr(myFunc,"count",0) + 1
print myFunc.count
return
if __name__ == "__main__":
while getattr(myFunc,"count",0) < 5:
myFunc()
view raw staticvar.py hosted with ❤ by GitHub

No comments:

Post a Comment