Python 3.7 is the next big release for python 3 which is expected to be officially released on 15 June 2018. The last release python 3.6 was released on 23 December 2016 which is long time in IT world.

In this post:

Update Python 3.7.0 is the last major released on 27 June 2018 and it contains many new features and changes:

  • Data Classes
  • Built-in breakpoints
  • Context Variables
  • Time functions with nanosecond resolution

Python 2 vs Python 3 in 2018

Python 3 was released in 2008 and ten years later there are still big amount of python 2 users. For Python 2 the official end-of-life date is in 2020 which means that support from the community will end in less than 2 years. After that you'll need to find ways to fix issues and solve vulnerabilities if any by yourself.

Operating systems like Ubuntu 18.04 are changing the default python package to be python 3 ( python 2 was default for long time). Python version 2.7.14 is supposed to be the last major release in the 2.7. No plans for new features or versions. Only security and bug updates will be going in from now until the end of python 2.

Another point why to move to python 3 is the changes in the language itself. New functions, new features and modules will make your life easier. You have improvements in many areas like: tab and space indentation, unicode support and exception handling, memory improvements and function annotations etc.

Update July 2018

Yesterday I found a site which count down the time until python 2 is going to be closed. You can check this site from this link:

Python 2.7 will retire in...

It's a good idea to check the official migration guide for porting python 2 to python 3:

Porting Python 2 Code to Python 3

This is what the site is saying:

Python 2.7 will not be maintained past 2020. Originally, there was no official date. Recently, that date has been updated to January 1, 2020. This clock has been updated accordingly. My original idea was to throw a Python 2 Celebration of Life party at PyCon 2020, to celebrate everything Python 2 did for us. That idea still stands. (If this sounds interesting to you, email [email protected]).

Python 3.7 what's new

You can check the full list of changes in the official documentation here:

What’s New In Python 3.7

and here:

PEP 537 -- Python 3.7 Release Schedule

The most interesting changes for me are:

PEP 553: Built-in breakpoint()

A new built-in called breakpoint() which makes it easy and consistent to enter the Python debugger. The environment variable PYTHONBREAKPOINT can be set to the callable of your debugger of choice. Set PYTHONBREAKPOINT=0 to completely disable built-in breakpoint().

PEP 564: Add new time functions with nanosecond resolution

Add new 'nanosecond' versions of existing functions of time module like: time.clock_gettime_ns() and time.clock_settime_ns(). They will return a number of nanoseconds as a Python int which is giving better accuracy.

PEP 540: New UTF-8 mode

New UTF-8 mode(enabled by default in the POSIX locale, but otherwise disabled) by default to ignore the locale. It uses the UTF-8 encoding, and change sys.stdin and sys.stdout.

PEP 557: Data Classes

New module dataclasses is added which provides a class decorator dataclass(). This module will inspect the class's variable annotations and will use them.

For example:

class Point:
    x: float
    y: float
    z: float = 0.0

p = Point(1.5, 2.5)
print(p)   # produces "Point(x=1.5, y=2.5, z=0.0)

PEP 567: Context Variables

New module contextvars providing APIs to manage, store, and access non-local state. Context variables are natively supported in asyncio and are ready to be used without any extra configuration.

PEP 562: Customization of access to module attributes

Customization and control over the access of module attributes will be possible ( example is managing deprecation warnings).

Ubuntu Check python version and install latest

If you are working with Ubuntu you can check your version by typing:

python -V

Installing python for Ubuntu 18.04 minimal can be done by:

for python 3

sudo apt install python3-minimal

for python 2

sudo apt0get install python-minimal

Full python:

sudo apt install python3

for python 2

sudo apt0get install python