© Joannah Nanjekye 2017
Joannah NanjekyePython 2 and 3 Compatibilityhttps://doi.org/10.1007/978-1-4842-2955-2_5

5. Package Imports

Joannah Nanjekye
(1)
Kampala, Uganda
 
Python 3 comes with syntax changes for imports within a package by requiring us to use the relative imports syntax. There are libraries with a different package import for each Python version; for example, the URL library urllib.request is for Python 3, and urllib2 is for Python 2. This chapter describes how to ensure compatibility with relative imports and how to import a suitable package based on the Python version.
Before I go in detail about compatibility with package imports, let me take you a step back and go through Python’s importing infrastructure.

Python Imports

Like any other ...

Get Python 2 and 3 Compatibility: With Six and Python-Future Libraries now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.