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

后端 未结 9 919
面向向阳花
面向向阳花 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:01

    I'm guessing you have something like:

    import module_foo
    ...
    import sys
    # check sys.version
    

    but module_foo requires a particular version as well? This being the case, it is perfectly valid to rearrange your code thus:

    import sys
    # check sys.version
    import module_foo
    

    Python does not require that imports, aside from from __future__ import [something] be at the top of your code.

提交回复
热议问题