[sapug] Python and Revision Control tagging

Daryl Tester Daryl.Tester at iocane.com.au
Mon Mar 6 11:13:47 CET 2006


A nice little Python idiom I picked up somewhere along the
line.  If you have your Python code under RCS/CVS style
revision control, and you stick the following line in your
module:

__version__ = '$Name: $'[7:-2] or '$Revision: $'[11:-2]

then the symbolic name (1st choice) or revision ID gets
assigned to the __version__ attribute.  The neat part
lies in the string slicing; if a non-symbolic branch is
checked out, then the '$Name: $' portion isn't set by
RCS/CVS, and the [7:-2] portion of the string evaluates
to empty causing the right half of the string to be
evaluated instead.

Well, I thought it was neat.

-- 
Regards,
  Daryl Tester, IOCANE Pty. Ltd.


More information about the sapug mailing list