上QQ阅读APP看书,第一时间看更新
Python 2 and Python 3
A massive source of confusion for beginners is that there are two versions of Python on Raspberry Pi (Version 2.7 and Version 3.6), which are not compatible with each other, so code written for Python 2.7 may not run with Python 3.6 (and vice versa).
The Python Software Foundation is continuously working to improve and move forward with the language, which sometimes means they have to sacrifice backward compatibility to embrace new improvements (and, importantly, remove redundant and legacy ways of doing things).
Supporting Python 2 and Python 3
There are many tools that will ease the transition from Python 2 to Python 3, including converters such as 2to3 , which will parse and update your code to use Python 3 methods. This process is not perfect, and in some cases you'll need to manually rewrite sections and fully retest everything. You can write the code and libraries that will support both. The import __future__ statement allows you to import the friendly methods of Python 3 and run them using Python 2.7.
There are many tools that will ease the transition from Python 2 to Python 3, including converters such as 2to3 , which will parse and update your code to use Python 3 methods. This process is not perfect, and in some cases you'll need to manually rewrite sections and fully retest everything. You can write the code and libraries that will support both. The import __future__ statement allows you to import the friendly methods of Python 3 and run them using Python 2.7.