Michael C. Neel
neel at mediapulse.com
Tue Dec 2 14:30:41 EST 2003
Most modules have a __version__ member, and the help() built-in method even looks for this variable and uses it to display the version of the file: >>>import cgi >>>cgi.__version__ '2.6' >>>help(cgi) ...skipping... DATA __all__ = ['MiniFieldStorage', 'FieldStorage', 'FormContentDict', 'SvF... __version__ = '2.6' logfile = '' logfp = None maxlen = 0 VERSION 2.6 >>> I have not read or seen anything saying the "pythonic" way of versioning a module is by try/except blocks testing to see if variable exist. I have however seen this from PEP 8: Version Bookkeeping If you have to have RCS or CVS crud in your source file, do it as follows. __version__ = "$Revision: 1.20 $" # $Source: /cvsroot/python/python/nondist/peps/pep-0008.txt,v $ These lines should be included after the module's docstring, before any other code, separated by a blank line above and below. Which implies to me that __version__ is a pythonic way of versioning a module/code file, though it doesn't seem to be as standard as __doc__. Mike > -----Original Message----- > From: Gustavo Córdova Avila [mailto:gustavo.cordova at q-voz.com] > Sent: Tuesday, December 02, 2003 1:47 PM > To: Michael C. Neel > Cc: mod_python at modpython.org > Subject: Re: [mod_python] Getting mod_python version > > > This is the correct, "pythonic" way of doing things. > > I'd recommend using "except AttributeError:" instead of a naked > "except:" btw. > > -gustavo > > Michael C. Neel wrote: > > >Hi all, > > > > I don't know if it's not there, or I'm just overlooking it, but > >I can seem for a way in code to get the version of > mod_python. I have > >some "default" modules I use, and I am trying to make them > work with any > >mod_python version. Right now I'm doing try block, like such: > > > > # Get username/password from client > > pw = req.get_basic_auth_pw() > > try: > > # mod_python 2.x > > user = req.connection.user > > except: > > # mod_python 3.x > > user = req.user > > > > ...but I'd rather be able to get the version directly. > > > >Mike > > > >_______________________________________________ > >Mod_python mailing list > >Mod_python at modpython.org > >http://mailman.modpython.org/mailman/listinfo/mod_python > > > > > > > > > >
|