Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python version change
#1
I have written Python code in Python 2.7.14 version and now i am asked to change to 3.6 version.
My queries:

1.will I be able to run the same code it python 3.6 with minimal changes?
2.Do libraries also vary in 3.6 from those used in python 2.7.14??
3.will the import statements like "from ABC import xyz" also vary from both these versions
Reply
#2
(Jul-19-2018, 12:53 PM)saisankalpj Wrote: 1.will I be able to run the same code it python 3.6 with minimal changes?
it's difficult to say without seeing actual code

(Jul-19-2018, 12:53 PM)saisankalpj Wrote: 2.Do libraries also vary in 3.6 from those used in python 2.7.14??
again - there are differences, but if your code is affected depends. it's difficult to say without seeing actual code.

(Jul-19-2018, 12:53 PM)saisankalpj Wrote: 3.will the import statements like "from ABC import xyz" also vary from both these versions
depends if your code uses libraries that has changed. For example its Tkinter in python 2, but tkinter in python3.

There is 2to3 tool that can help with the convertion
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
As mention bye @buran use 2to3.py that comes with python.
# greet.py
# Python 2.7
def greet(name):
    return("Hello, {}!".format(name))

name = raw_input("What's your name? ")
print 'Hello {}'.format(greet(name)
From command line:
C:\Python37\Tools\scripts
λ python 2to3.py -w greet.py
After Python 3 code:
# greet.py
# Python 3.7
def greet(name):
    return("Hello, {}!".format(name))

name = input("What's your name? ")
print('Hello {}'.format(greet(name)))
Reply
#4
(Jul-19-2018, 01:48 PM)snippsat Wrote: As mention bye @buran use 2to3.py that comes with python.
# greet.py # Python 2.7 def greet(name): return("Hello, {}!".format(name)) name = raw_input("What's your name? ") print 'Hello {}'.format(greet(name)
From command line:
C:\Python37\Tools\scripts λ python 2to3.py -w greet.py
After Python 3 code:
# greet.py # Python 3.7 def greet(name): return("Hello, {}!".format(name)) name = input("What's your name? ") print('Hello {}'.format(greet(name)))
Will the 2to3 library solve the entire issue automatically, or will i have to make some changes manually too apart from what changes the 2 to 3library makes.
Will the 2 to 3 tool also convert the ‘libraries of 2’ to the libraries of 3 automatically

(Jul-19-2018, 01:19 PM)buran Wrote:
saisankalpj dateline="<a href="tel:1532004801">1532004801</a>' Wrote: 1.will I be able to run the same code it python 3.6 with minimal changes?
it's difficult to say without seeing actual code
saisankalpj dateline="<a href="tel:1532004801">1532004801</a>' Wrote: 2.Do libraries also vary in 3.6 from those used in python 2.7.14??
again - there are differences, but if your code is affected depends. it's difficult to say without seeing actual code.
saisankalpj dateline="<a href="tel:1532004801">1532004801</a>' Wrote: 3.will the import statements like "from ABC import xyz" also vary from both these versions
depends if your code uses libraries that has changed. For example its Tkinter in python 2, but tkinter in python3. There is 2to3 tool that can help with the convertion
Will the 2to3 library solve the entire issue automatically, or will i have to make some changes manually too apart from what changes the 2 to 3library makes.
Will the 2 to 3 tool also convert the ‘libraries of 2’ to the libraries of 3 automatically
Reply
#5
run 2to3 tool and will get your answer

from the docs
Quote:Sometimes 2to3 will find a place in your source code that needs to be changed, but 2to3 cannot fix automatically. In this case, 2to3 will print a warning beneath the diff for a file. You should address the warning in order to have compliant 3.x code.

(Jul-19-2018, 05:14 PM)saisankalpj Wrote: Will the 2 to 3 tool also convert the ‘libraries of 2’ to the libraries of 3 automatically
what do you mean by that?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  run part of a script with a different version of Python jdog 2 444 Jan-09-2024, 08:49 PM
Last Post: jdog
  How to find out from outside Python (in Windows) the current version of Python? pstein 4 730 Oct-04-2023, 10:01 AM
Last Post: snippsat
  How to resolve version conflicts in Python? taeefnajib 0 908 Apr-27-2023, 08:37 PM
Last Post: taeefnajib
  Python venv and PIP version issue JanOlvegg 2 1,252 Feb-22-2023, 02:22 AM
Last Post: JanOlvegg
  Python Version upgrade nitinkukreja 1 894 Feb-04-2023, 10:27 PM
Last Post: Larz60+
  Can't update new python version on Pycharm GOKUUUU 6 3,793 Jul-23-2022, 09:24 PM
Last Post: GOKUUUU
  Building python (3.9.5) with different libexpat version (2.4.6) raghupcr 0 1,304 Feb-25-2022, 11:29 AM
Last Post: raghupcr
  Python keeps running the old version of the code quest 2 3,748 Jan-20-2022, 07:34 AM
Last Post: ThiefOfTime
  db migration(db version control) for python lubaz 2 2,755 May-30-2021, 01:36 PM
Last Post: lubaz
  Error on Python Version? ErnestTBass 6 3,488 Dec-09-2020, 04:02 PM
Last Post: ErnestTBass

Forum Jump:

User Panel Messages

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