random.py

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Apr 26 02:57:40 EDT 2007


En Thu, 26 Apr 2007 02:08:42 -0300, Bill Jackson <jackson at hotmail.com>  
escribió:

> 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.


-- 
Gabriel Genellina



More information about the Python-list mailing list