Checking Python version in a program

Oleg Broytmann phd at phd.russ.ru
Thu Mar 2 12:34:50 EST 2000


On Thu, 2 Mar 2000, Preston Landers wrote:
> My program Pagecast (http://pagecast.sourceforge.net) requires some
> library (not language) features of Python 1.5.2.
> 
> I would like to put a semi-intelligent Python version check in the
> program to give the users a meaningful error message.

   Do not check version - this will bound poor user to one version. Check
for the feature you need. You need a library? Try to import it and fall
back gracefully:

try:
   import pagecast_lib
except ImportError:
   print_error()

if not pagecast_lib.has_key("I_need_IT"):
   print_another_error()

Oleg.
---- 
    Oleg Broytmann      Foundation for Effective Policies      phd at phd.russ.ru
           Programmers don't die, they just GOSUB without RETURN.





More information about the Python-list mailing list