Python

What is the __future__ module for in Python?

January 4, 2022

What is the __future__ module for in Python?

In this article, we’ll learn what is the __future__ module in Python, and how we can benefit from using it in our projects.

__future__ module for in Python cover

Hey you programmer, how are you? Let’s learn more about Python!

Basically, the __future__ module is a way to use future features that are planned for the next versions of the Python language in your software

That’s why we use the following syntax:

from __future__ import

We are importing something that is not yet available for us to work on.

A classic example is when we want to use something from version 3 in Python version 2

Which is still used in many libraries

Let’s look at these print instructions:

# Python 2
print "Hello World"

# Python 3
print("Hello World")

We could run this feature if we use __future__ in a Python version 2 program

version migrations

In addition, you can gradually migrate your program to Python 3

With the help of __future__ you only import the modules you want to adapt

Getting rid of a giant incompatibility just by updating the version

So this process can be gradual as you evolve your software

Remember that it is also important to leave your Pythonic code, following these instructions that the language documentation preaches

And that every self-respecting Python programmer should know

Conclusion

In this article, we learned  what the __future__ module is for

Which is nothing more than a feature that helps us import future features from new Python versions

So you can use some of them in our software or migrate it to the future version little by little

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x