How to write Python code that is able to properly require a minimal python version?

后端 未结 9 773
面向向阳花
面向向阳花 2021-01-31 01:33

I would like to see if there is any way of requiring a minimal python version.

I have several python modules that are requiring Python 2.6 due to the new exception handl

9条回答
  •  心在旅途
    2021-01-31 02:13

    You can take advantage of the fact that Python will do the right thing when comparing tuples:

    #!/usr/bin/python
    import sys
    MIN_PYTHON = (2, 6)
    if sys.version_info < MIN_PYTHON:
        sys.exit("Python %s.%s or later is required.\n" % MIN_PYTHON)
    

提交回复
热议问题