Object versions in Python

Martin von Loewis loewis at informatik.hu-berlin.de
Sun Jan 6 11:32:09 EST 2002


"Graham Ashton" <graz at mindless.com> writes:

> Stick a variable (in the module scope) that's called __version__.
> 
> e.g.
> 
> __version__ = "0.8.1"
> 
> I've no idea what to do for classes though, if anything.

It's also a question of what you want to do with the version. If you
just want to check for a minimum required version, or a range of
acceptable versions, the __version__ approach is fine and extends
nicely to classes. For easier processing, it is also common to add
a second constant

version_info = (0,8,1)

so that things like

  (0,6) <= version_info <= (1,2)

work nicely; __version__ is more for the human reader (although
distutils offers functions to convert between the two).

If you want to install several versions in parallel, you need to name
things differently:

class Foo_1_0:...
class Foo_1_1:...
Foo = Foo_1_1

So anybody using mymod.Foo will get the most recent version; if
somebody needs an older version, they need to qualify it explicitly.

HTH,
Martin



More information about the Python-list mailing list