random.py

B

Bill Jackson

In random.py (Python 2.5.1), line 86 says:

VERSION = 2 # used by getstate/setstate

Then, in the definition of Random.setstate, we have:

if version == 2:

Why is it not:

if version == self.VERSION:
 
G

Gabriel Genellina

In random.py (Python 2.5.1), line 86 says:

VERSION = 2 # used by getstate/setstate

Then, in the definition of Random.setstate, we have:

if version == 2:

Why is it not:

if version == self.VERSION:

Just thinking: Possibly because that conditional tries to detect whether
the following code block applies or not; the code knows how to handle
"version 2" data, and that happens to be the current version, but that's
just because there is not a "version 3" (yet).
Let's say, in the future, there is a version 3; the code could become:

if version == 3:
# new code to handle version 3 data
elif version == 2:
# code to handle version 2 data
# this is the current contents
else:
# error message, as right now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top