python3.x and python2.x version compatibility issues __python

Source: Internet
Author: User
python3.x and python2.x version compatibility issues
Reorganization and renamingStandard library

Python's standard library has been reorganized in Python 3 for consistency and ease of use. All module names now conform to the style of Python code, PEP 8[1] and some modules are merged.

2to3 contains a retainer that can handle all of these, so this chapter is more about whether you need to support the interest of Python 2 and Python 3 without 2to3 conversion.

The six module [2] supports the consolidation of most reorganized standard libraries. You can import a restructured module from Six.moves:

>>> from six.moves import Cstringio

In Python 2 This is equivalent to:

>>> from Cstringio import Stringio

However in Python 3 this would be equivalent to:

>>> from IO import Stringio

This is also easy if you want to not convert and don't want to use the six module at the same time Python 2 and Python 3. You just have to try. Import from one location, catch errors, and then import from another location. It has nothing to do with where you put Python 3, either before or after, and it can work equally well:

>>> try:
... from io import Stringio ...
except Importerror:
... from Cstringio import String Io

This table contains the renaming and reorganization of all the standard libraries except for the Urllib, URLLIB2, and urlparse reorganization of the other tables:

Python 2-name word Python 3-name Word Six name
anydbm Dbm
Basehttpserver Http.server Basehttpserver
__builtin__ Builtins Builtins
Cgihttpserver Http.server Cgihttpserver
Configparser Configparser Configparser
Copy_reg Copyreg Copyreg
Cpickle Pickle Cpickle
CProfile Profile
Cstringio.stringio Io. Stringio Cstringio
Cookies Http.cookies Http_cookies
Cookielib Http.cookiejar Http_cookiejar
Dbhash Dbm.bsd
Dbm dbm.ndbm
Dumbdb Dbm.dumb
Dialog Tkinter.dialog Tkinter_dialog
Docxmlrpcserver Xmlrpc.server
FileDialog Tkinter. FileDialog Tkinter_filedialog
Fixtk Tkinter._fix
gdbm Dbm.gnu
Htmlentitydefs Html.entities Html_entities
Htmlparser Html.parser Html_parser
Httplib Http.client Http_client
Markupbase _markupbase
Queue Queue Queue
Repr Reprlib Reprlib
Robotparser Urllib.robotparser Urllib_robotparser
Scrolledtext Tkinter.scolledtext Tkinter_scrolledtext
Simpledialog Tkinter.simpledialog Tkinter_simpledialog
Simplehttpserver Http.server Simplehttpserver
Simplexmlrpcserver Xmlrpc.server
Stringio.stringio Io. Stringio
Socketserver Socketserver Socketserver
Test.test_support Test.support Tkinter
Tkinter Tkinter Tkinter
Tix Tkinter.tix Tkinter_tix
Tkconstants Tkinter.constants Tkinter_constants
Tkcolorchooser Tkinter.colorchooser Tkinter_colorchooser
Tkcommondialog Tkinter.commondialog Tkinter_commondialog
Tkdnd Tkinter.dnd Tkinter_dnd
Tkfiledialog Tkinter.filedialog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.