How to write code that works in both Python 2 and Python 3?

前端 未结 6 440
死守一世寂寞
死守一世寂寞 2021-01-03 02:28

A Django website I maintain currently uses Python 2.7 but I know that I\'ll have to upgrade it to Python 3 in a couple of months. If I\'m writing code right now that has to

6条回答
  •  别那么骄傲
    2021-01-03 02:41

    you can import the future package

    from future import ....
    

    nested_scopes 2.1.0b1 2.2 PEP 227: Statically Nested Scopes

    generators 2.2.0a1 2.3 PEP 255: Simple Generators

    division 2.2.0a2 3.0 PEP 238: Changing the Division Operator

    absolute_import 2.5.0a1 3.0 PEP 328: Imports: Multi-Line and Absolute/Relative

    with_statement 2.5.0a1 2.6 PEP 343: The “with” Statement

    print_function 2.6.0a2 3.0 PEP 3105: Make print a function

    unicode_literals 2.6.0a2 3.0 PEP 3112: Bytes literals in Python 3000

提交回复
热议问题