Faqts : Business : Programming : Shopping For You : PHP : Common Problems : Files : Tips and Tricks

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

32 of 43 people (74%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I check that the Python version is recent enough to run my program?

Dec 18th, 2009 12:09
new acct, sheana krat, Nathan Wallace, Fredrik Lundh, Oleg Broytmann


Note that (1, 5, 2) < (1, 6).  in other words, this will do what you
want:

  import sys
  version = sys.version_info[:3]
  if map(int, version) < (1, 5, 2):
    print "sorry"

I can be better to not check the version - this will bound poor user to
one version. Instead, 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 "I_need_IT" not in pagecast_lib:
    print_another_error()