Python Forum

Full Version: Python version change
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
(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
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)))
(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
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?