Re: change of random state when pyc created??
Alan Isaac wrote:
There is nothing wrong with the random module -- you get the same numbers on
every run. When there is no pyc-file Python uses some RAM to create it and
therefore your GridPlayer instances are located in different memory
locations and get different hash values. This in turn affects the order in
which they occur when you iterate over the GridPlayer.play ers_played set.
Here is a minimal example:
import test # sic
class T:
def __init__(self, name):
self.name = name
def __repr__(self):
return "T(name=%r) " % self.name
if __name__ == "__main__":
print set(T(i) for i in range(4))
$ python2.5 test.py
set([T(name=2), T(name=1), T(name=0), T(name=3)])
$ python2.5 test.py
set([T(name=3), T(name=1), T(name=0), T(name=2)])
$ python2.5 test.py
set([T(name=3), T(name=1), T(name=0), T(name=2)])
$ rm test.pyc
$ python2.5 test.py
set([T(name=2), T(name=1), T(name=0), T(name=3)])
Peter
Alan Isaac wrote:
This may seem very strange, but it is true.
If I delete a .pyc file, my program executes with a different state!
If I delete a .pyc file, my program executes with a different state!
Can someone explain this to me?
every run. When there is no pyc-file Python uses some RAM to create it and
therefore your GridPlayer instances are located in different memory
locations and get different hash values. This in turn affects the order in
which they occur when you iterate over the GridPlayer.play ers_played set.
Here is a minimal example:
import test # sic
class T:
def __init__(self, name):
self.name = name
def __repr__(self):
return "T(name=%r) " % self.name
if __name__ == "__main__":
print set(T(i) for i in range(4))
$ python2.5 test.py
set([T(name=2), T(name=1), T(name=0), T(name=3)])
$ python2.5 test.py
set([T(name=3), T(name=1), T(name=0), T(name=2)])
$ python2.5 test.py
set([T(name=3), T(name=1), T(name=0), T(name=2)])
$ rm test.pyc
$ python2.5 test.py
set([T(name=2), T(name=1), T(name=0), T(name=3)])
Peter
Comment