Python Forum
changing much of my Python code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
changing much of my Python code
#6
(Apr-29-2019, 06:56 AM)Gribouillis Wrote: If this is python 2 code that you want to convert to python 3, use the 2to3 utility. It will remove the unnecessary __future__ imports and probably keep the rest of the code working. Note that __future__ imports still exist in python 3.

i had been writing my code to work in both Python2 and Python3. now that Python2 is less than a year from EOL, i have decided to drop it entirely and only write for Python3. i don't need to use the 2to3 utility because all my code already works in Python3 (and most probably still also works in Python2, but i really don't care about that, anymore.

what do the __future__ imports do in Python3? i thought they did nothing, though i could believe that if a Python4 ever comes out that __future__ could have a new use.

if the 2to3 utility removes the __future__ imports then i suppose it is safe for me to do so. just doing only that should have no effect on running that code under Python3, right? if it runs OK with the __future__ imports under Python3, then it should also run without, right?

(Apr-29-2019, 09:58 AM)DeaD_EyE Wrote: You can add:
from __future__ import annotations
PEP 563

The __future__ module is still used to introduce changes.
https://docs.python.org/3/library/__future__.html

none of my code imports annotations (yet). i can add that import if/when i use annotations, right?

Output:
lt2a/phil /home/phil 20> rls +f|pygrep|whathas annotations lt2a/phil /home/phil 21> rls +f|pygrep|whathas __future__|lc 10306 lt2a/phil /home/phil 22>
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
changing much of my Python code - by Skaperen - Apr-28-2019, 08:44 PM
RE: changing much of my Python code - by Skaperen - Apr-29-2019, 03:52 AM
RE: changing much of my Python code - by Skaperen - Apr-29-2019, 07:01 PM
RE: changing much of my Python code - by DeaD_EyE - Apr-29-2019, 09:58 AM
RE: changing much of my Python code - by Skaperen - May-04-2019, 02:39 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020