[{"data":1,"prerenderedAt":39},["ShallowReactive",2],{"article-python-future-module-33ph":3},{"type_of":4,"id":5,"title":6,"description":7,"readable_publish_date":8,"slug":9,"path":10,"url":11,"comments_count":12,"public_reactions_count":13,"collection_id":14,"published_timestamp":15,"language":16,"subforem_id":17,"positive_reactions_count":13,"cover_image":18,"social_image":19,"canonical_url":11,"created_at":15,"edited_at":20,"crossposted_at":14,"published_at":15,"last_comment_at":15,"reading_time_minutes":21,"tag_list":22,"tags":23,"body_html":28,"body_markdown":29,"user":30},"article",338298,"Python __future__ module","❓ What is future module btw?     future is python built-in module. It serves three purposes,...","May 18 '20","python-future-module-33ph","\u002Fashraful\u002Fpython-future-module-33ph","https:\u002F\u002Fdev.to\u002Fashraful\u002Fpython-future-module-33ph",0,6,null,"2020-05-18T15:31:29Z","en",1,"https:\u002F\u002Fmedia2.dev.to\u002Fdynamic\u002Fimage\u002Fwidth=1000,height=420,fit=cover,gravity=auto,format=auto\u002Fhttps%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7nwejejtyes28z6s57fh.jpg","https:\u002F\u002Fmedia2.dev.to\u002Fdynamic\u002Fimage\u002Fwidth=1000,height=500,fit=cover,gravity=auto,format=auto\u002Fhttps%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7nwejejtyes28z6s57fh.jpg","2026-07-18T11:41:58Z",2,"python, builtin, modules, functional",[24,25,26,27],"python","builtin","modules","functional","\u003Ch2>\n  \u003Ca name=\"question-what-is-future-module-btw\" href=\"#question-what-is-future-module-btw\">\n  \u003C\u002Fa>\n  ❓ What is \u003Cstrong>future\u003C\u002Fstrong> module btw?\n\u003C\u002Fh2>\n\n\u003Cul>\n\u003Cli>\n\u003Cstrong>future\u003C\u002Fstrong> is python built-in module.\u003C\u002Fli>\n\u003Cli>It serves three purposes, \u003C\u002Fli>\n\u003Cli>To avoid confusing existing tools that analyze import statements and expect to find the modules they’re importing.\u003C\u002Fli>\n\u003Cli>To ensure future statements run under release prior to 2.1 at least yield runtime exceptions\u003C\u002Fli>\n\u003Cli>\n\u003Cstrong>future\u003C\u002Fstrong> will allow you to use a feature from the future.\u003C\u002Fli>\n\u003C\u002Ful>\n\n\u003Cblockquote>\n\u003Cp>I know it sounds crazy for the first time you heard. But it's real. Let's dig into this.\u003C\u002Fp>\n\u003C\u002Fblockquote>\n\n\u003Ch2>\n  \u003Ca name=\"fire-more-about-future\" href=\"#fire-more-about-future\">\n  \u003C\u002Fa>\n  🔥 More about \u003Cstrong>future\u003C\u002Fstrong>.\n\u003C\u002Fh2>\n\n\u003Cp>\u003Cstrong>future\u003C\u002Fstrong> module introduced from python 2.1. On the source of cpython's \u003Ccode>__future__.py\u003C\u002Fcode> there is defined each future feature like following,\u003Cbr>\n\u003C\u002Fp>\n\n\u003Cdiv class=\"highlight js-code-highlight\">\n\u003Cpre class=\"highlight python\">\u003Ccode>\u003Cspan class=\"n\">FeatureName\u003C\u002Fspan> \u003Cspan class=\"o\">=\u003C\u002Fspan> \u003Cspan class=\"nf\">_Feature\u003C\u002Fspan>\u003Cspan class=\"p\">(\u003C\u002Fspan>\u003Cspan class=\"n\">OptionalRelease\u003C\u002Fspan>\u003Cspan class=\"p\">,\u003C\u002Fspan> \u003Cspan class=\"n\">MandatoryRelease\u003C\u002Fspan>\u003Cspan class=\"p\">,\u003C\u002Fspan> \u003Cspan class=\"n\">CompilerFlag\u003C\u002Fspan>\u003Cspan class=\"p\">)\u003C\u002Fspan>\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cdiv class=\"highlight__panel js-actions-panel\">\n\u003Cdiv class=\"highlight__panel-action js-fullscreen-code-action\">\n    \u003Csvg xmlns=\"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\">\u003Ctitle>Enter fullscreen mode\u003C\u002Ftitle>\n    \u003Cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\">\u003C\u002Fpath>\n\u003C\u002Fsvg>\n\n    \u003Csvg xmlns=\"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\">\u003Ctitle>Exit fullscreen mode\u003C\u002Ftitle>\n    \u003Cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\">\u003C\u002Fpath>\n\u003C\u002Fsvg>\n\n\u003C\u002Fdiv>\n\u003C\u002Fdiv>\n\u003C\u002Fdiv>\n\n\n\n\u003Cp>Where, normally, OptionalRelease is less than MandatoryRelease, and both are 5-tuples of the same form as sys.version_info\u003Cbr>\n\u003C\u002Fp>\n\n\u003Cdiv class=\"highlight js-code-highlight\">\n\u003Cpre class=\"highlight python\">\u003Ccode>\u003Cspan class=\"n\">sys\u003C\u002Fspan>\u003Cspan class=\"p\">.\u003C\u002Fspan>\u003Cspan class=\"nf\">version_info\u003C\u002Fspan>\u003Cspan class=\"p\">(\u003C\u002Fspan>\u003Cspan class=\"n\">major\u003C\u002Fspan>\u003Cspan class=\"o\">=\u003C\u002Fspan>\u003Cspan class=\"mi\">3\u003C\u002Fspan>\u003Cspan class=\"p\">,\u003C\u002Fspan> \u003Cspan class=\"n\">minor\u003C\u002Fspan>\u003Cspan class=\"o\">=\u003C\u002Fspan>\u003Cspan class=\"mi\">8\u003C\u002Fspan>\u003Cspan class=\"p\">,\u003C\u002Fspan> \u003Cspan class=\"n\">micro\u003C\u002Fspan>\u003Cspan class=\"o\">=\u003C\u002Fspan>\u003Cspan class=\"mi\">1\u003C\u002Fspan>\u003Cspan class=\"p\">,\u003C\u002Fspan> \u003Cspan class=\"n\">releaselevel\u003C\u002Fspan>\u003Cspan class=\"o\">=\u003C\u002Fspan>\u003Cspan class=\"sh\">'\u003C\u002Fspan>\u003Cspan class=\"s\">final\u003C\u002Fspan>\u003Cspan class=\"sh\">'\u003C\u002Fspan>\u003Cspan class=\"p\">,\u003C\u002Fspan> \u003Cspan class=\"n\">serial\u003C\u002Fspan>\u003Cspan class=\"o\">=\u003C\u002Fspan>\u003Cspan class=\"mi\">0\u003C\u002Fspan>\u003Cspan class=\"p\">)\u003C\u002Fspan>\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cdiv class=\"highlight__panel js-actions-panel\">\n\u003Cdiv class=\"highlight__panel-action js-fullscreen-code-action\">\n    \u003Csvg xmlns=\"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\">\u003Ctitle>Enter fullscreen mode\u003C\u002Ftitle>\n    \u003Cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\">\u003C\u002Fpath>\n\u003C\u002Fsvg>\n\n    \u003Csvg xmlns=\"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\">\u003Ctitle>Exit fullscreen mode\u003C\u002Ftitle>\n    \u003Cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\">\u003C\u002Fpath>\n\u003C\u002Fsvg>\n\n\u003C\u002Fdiv>\n\u003C\u002Fdiv>\n\u003C\u002Fdiv>\n\n\n\n\u003Ch2>\n  \u003Ca name=\"collision-okay-enough-talk-lets-see-the-usage\" href=\"#collision-okay-enough-talk-lets-see-the-usage\">\n  \u003C\u002Fa>\n  💥 Okay! Enough talk. Let's see the usage.\n\u003C\u002Fh2>\n\n\u003Cp>Suppose, you are using python2(Though python 2 is dead. Just take it an example). You want to use the print function from python3. But how you can do it? Here comes the \u003Cstrong>future\u003C\u002Fstrong> module.\u003C\u002Fp>\n\n\u003Cp>Python 3 Console\u003Cbr>\n\u003C\u002Fp>\n\n\u003Cdiv class=\"highlight js-code-highlight\">\n\u003Cpre class=\"highlight console\">\u003Ccode>\u003Cspan class=\"gp\">&gt;\u003C\u002Fspan>\u003Cspan class=\"o\">&gt;&gt;\u003C\u002Fspan>\n\u003Cspan class=\"gp\">&gt;\u003C\u002Fspan>\u003Cspan class=\"o\">&gt;&gt;\u003C\u002Fspan> print\u003Cspan class=\"o\">(\u003C\u002Fspan>\u003Cspan class=\"s1\">'Hello'\u003C\u002Fspan>, \u003Cspan class=\"s1\">'World'\u003C\u002Fspan>, \u003Cspan class=\"nv\">sep\u003C\u002Fspan>\u003Cspan class=\"o\">=\u003C\u002Fspan>\u003Cspan class=\"s1\">', '\u003C\u002Fspan>, \u003Cspan class=\"nv\">end\u003C\u002Fspan>\u003Cspan class=\"o\">=\u003C\u002Fspan>\u003Cspan class=\"s1\">'\\n'\u003C\u002Fspan>\u003Cspan class=\"o\">)\u003C\u002Fspan>\n\u003Cspan class=\"go\">Hello, World\n\u003C\u002Fspan>\u003Cspan class=\"gp\">&gt;\u003C\u002Fspan>\u003Cspan class=\"o\">&gt;&gt;\u003C\u002Fspan>\n\u003Cspan class=\"gp\">&gt;\u003C\u002Fspan>\u003Cspan class=\"o\">&gt;&gt;\u003C\u002Fspan>\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cdiv class=\"highlight__panel js-actions-panel\">\n\u003Cdiv class=\"highlight__panel-action js-fullscreen-code-action\">\n    \u003Csvg xmlns=\"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\">\u003Ctitle>Enter fullscreen mode\u003C\u002Ftitle>\n    \u003Cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\">\u003C\u002Fpath>\n\u003C\u002Fsvg>\n\n    \u003Csvg xmlns=\"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\">\u003Ctitle>Exit fullscreen mode\u003C\u002Ftitle>\n    \u003Cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\">\u003C\u002Fpath>\n\u003C\u002Fsvg>\n\n\u003C\u002Fdiv>\n\u003C\u002Fdiv>\n\u003C\u002Fdiv>\n\n\n\n\u003Cp>In python2 you need to do the following,\u003Cbr>\n\u003C\u002Fp>\n\n\u003Cdiv class=\"highlight js-code-highlight\">\n\u003Cpre class=\"highlight console\">\u003Ccode>\u003Cspan class=\"gp\">&gt;\u003C\u002Fspan>\u003Cspan class=\"o\">&gt;&gt;\u003C\u002Fspan>\n\u003Cspan class=\"gp\">&gt;\u003C\u002Fspan>\u003Cspan class=\"o\">&gt;&gt;\u003C\u002Fspan> from __future__ import print_function\n\u003Cspan class=\"gp\">&gt;\u003C\u002Fspan>\u003Cspan class=\"o\">&gt;&gt;\u003C\u002Fspan>\n\u003Cspan class=\"gp\">&gt;\u003C\u002Fspan>\u003Cspan class=\"o\">&gt;&gt;\u003C\u002Fspan> print\u003Cspan class=\"o\">(\u003C\u002Fspan>\u003Cspan class=\"s1\">'Hello'\u003C\u002Fspan>, \u003Cspan class=\"s1\">'World'\u003C\u002Fspan>, \u003Cspan class=\"nv\">sep\u003C\u002Fspan>\u003Cspan class=\"o\">=\u003C\u002Fspan>\u003Cspan class=\"s1\">', '\u003C\u002Fspan>, \u003Cspan class=\"nv\">end\u003C\u002Fspan>\u003Cspan class=\"o\">=\u003C\u002Fspan>\u003Cspan class=\"s1\">'\\n'\u003C\u002Fspan>\u003Cspan class=\"o\">)\u003C\u002Fspan>\n\u003Cspan class=\"go\">Hello, World\n\u003C\u002Fspan>\u003Cspan class=\"gp\">&gt;\u003C\u002Fspan>\u003Cspan class=\"o\">&gt;&gt;\u003C\u002Fspan>\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cdiv class=\"highlight__panel js-actions-panel\">\n\u003Cdiv class=\"highlight__panel-action js-fullscreen-code-action\">\n    \u003Csvg xmlns=\"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\">\u003Ctitle>Enter fullscreen mode\u003C\u002Ftitle>\n    \u003Cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\">\u003C\u002Fpath>\n\u003C\u002Fsvg>\n\n    \u003Csvg xmlns=\"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\">\u003Ctitle>Exit fullscreen mode\u003C\u002Ftitle>\n    \u003Cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\">\u003C\u002Fpath>\n\u003C\u002Fsvg>\n\n\u003C\u002Fdiv>\n\u003C\u002Fdiv>\n\u003C\u002Fdiv>\n\n\n\n\u003Cp>Here, I have imported print_fuction from \u003Cstrong>future\u003C\u002Fstrong> module. Then it's working as expected from python3. I hope you got it.\u003C\u002Fp>\n\n\u003Ch2>\n  \u003Ca name=\"flushed-available-future-functions\" href=\"#flushed-available-future-functions\">\n  \u003C\u002Fa>\n  😳 Available future functions\n\u003C\u002Fh2>\n\n\u003Cp>\u003Ccode>nested_scopes\u003C\u002Fcode>\u003Cbr>\n\u003Ccode>generators\u003C\u002Fcode>\u003Cbr>\n\u003Ccode>division\u003C\u002Fcode>\u003Cbr>\n\u003Ccode>absolute_import\u003C\u002Fcode>\u003Cbr>\n\u003Ccode>with_statement\u003C\u002Fcode>\u003Cbr>\n\u003Ccode>print_function\u003C\u002Fcode>\u003Cbr>\n\u003Ccode>unicode_literals\u003C\u002Fcode>\u003Cbr>\n\u003Ccode>barry_as_FLUFL\u003C\u002Fcode>\u003Cbr>\n\u003Ccode>generator_stop\u003C\u002Fcode>\u003Cbr>\n\u003Ccode>annotations\u003C\u002Fcode>\u003C\u002Fp>\n\n\u003Cp>See the source \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fpython\u002Fcpython\u002Fblob\u002F3.8\u002FLib\u002F__future__.py\" target=\"_blank\" rel=\"noopener noreferrer\">here\u003C\u002Fa>\u003C\u002Fp>\n\n\u003Cp>Good Luck 😃\u003C\u002Fp>\n\n","## :question: What is __future__ module btw?\n* __future__ is python built-in module.\n* It serves three purposes, \n* To avoid confusing existing tools that analyze import statements and expect to find the modules they’re importing.\n* To ensure future statements run under release prior to 2.1 at least yield runtime exceptions\n* __future__ will allow you to use a feature from the future.\n\n> I know it sounds crazy for the first time you heard. But it's real. Let's dig into this.\n\n## :fire: More about __future__.\n__future__ module introduced from python 2.1. On the source of cpython's `__future__.py` there is defined each future feature like following,\n```python\nFeatureName = _Feature(OptionalRelease, MandatoryRelease, CompilerFlag)\n```\nWhere, normally, OptionalRelease is less than MandatoryRelease, and both are 5-tuples of the same form as sys.version_info\n```python\nsys.version_info(major=3, minor=8, micro=1, releaselevel='final', serial=0)\n```\n\n## :collision: Okay! Enough talk. Let's see the usage.\nSuppose, you are using python2(Though python 2 is dead. Just take it an example). You want to use the print function from python3. But how you can do it? Here comes the __future__ module.\n\nPython 3 Console\n```console\n>>>\n>>> print('Hello', 'World', sep=', ', end='\\n')\nHello, World\n>>>\n>>>\n```\n\nIn python2 you need to do the following,\n```console\n>>>\n>>> from __future__ import print_function\n>>>\n>>> print('Hello', 'World', sep=', ', end='\\n')\nHello, World\n>>>\n```\nHere, I have imported print_fuction from __future__ module. Then it's working as expected from python3. I hope you got it.\n\n## :flushed: Available future functions\n`nested_scopes`\n`generators`\n`division`\n`absolute_import`\n`with_statement`\n`print_function`\n`unicode_literals`\n`barry_as_FLUFL`\n`generator_stop`\n`annotations`\n\nSee the source [here](https:\u002F\u002Fgithub.com\u002Fpython\u002Fcpython\u002Fblob\u002F3.8\u002FLib\u002F__future__.py)\n\nGood Luck :smiley:",{"name":31,"username":32,"twitter_username":33,"github_username":34,"user_id":35,"website_url":36,"profile_image":37,"profile_image_90":38},"Mohamad Ashraful Islam","ashraful","_ashraful","iashraful",30490,"https:\u002F\u002Fashraful.dev","https:\u002F\u002Fmedia2.dev.to\u002Fdynamic\u002Fimage\u002Fwidth=640,height=640,fit=cover,gravity=auto,format=auto\u002Fhttps%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F30490%2F9dc1ef64-0233-43b5-9127-79affd83cc43.jpg","https:\u002F\u002Fmedia2.dev.to\u002Fdynamic\u002Fimage\u002Fwidth=90,height=90,fit=cover,gravity=auto,format=auto\u002Fhttps%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F30490%2F9dc1ef64-0233-43b5-9127-79affd83cc43.jpg",1784633124094]