Possible Duplicate:
“Least Astonishment” in Python: The Mutable Default Argument
from random import random
def printNumber(num=random()):
print num
for i in range(10):
printNumber()
I want to see ten random numbers, but the ten random numbers are all the same!
Because the default arguments are only executed once, when the function is compiled.
From the Docs:
you can try something like this: