Migration of Python2 and Python3 using Modernize and Future - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Migration of Python2 and Python3 using Modernize and Future (/thread-36447.html) |
Migration of Python2 and Python3 using Modernize and Future - Rakshan - Feb-21-2022 I am working on the migration of files from Python2.7 to Python3+. As a part of preparation, I have come across utility 2to3, Modernize and Futurize 2To3 seems to be very simple and I have managed to try out examples. Since it is not backward compatible, it is suggested that Modernize and Futurize are better I installed the modernize library and Six as well, I have 2 versions of Python on my system (2.7 and 3.9) I have a sample(Test.py) python2 code. def greet(name): print "Hello, {0}!, How are you doing?" .format(name) print "Your name?" name = raw_input() greet(name)Now I go to the directory to run the command : python-modernize -w Test.pyI observe that the python file is migrated to python3. When I run the code with the python3 interpreter from the command line, it works as expected. New Test.py: from __future__ import print_function from six.moves import input def greet(name): print("Hello, {0}!, How are you doing?" .format(name)) print("Your name?") name = input() greet(name)However, since it promises backward compatibility, I expect it to run with Python2 interpreter as well When I do the following : C:\Python27\python.exe Test.pyI get an error: I uninstalled and installed the six library, but no success. What am I doing wrong here?
RE: Migration of Python2 and Python3 using Modernize and Future - Axel_Erfurt - Feb-21-2022 Did you installed six in python2? RE: Migration of Python2 and Python3 using Modernize and Future - Rakshan - Feb-21-2022 (Feb-21-2022, 12:20 PM)Axel_Erfurt Wrote: Did you installed six in python2? I have downloaded the tar.gz file and extracted it to C:\Python27/Tools/Libs/site-packages RE: Migration of Python2 and Python3 using Modernize and Future - Rakshan - Feb-21-2022 Rectified: problem was with the mulitple versions. I had to install the library in python2. but my pip install command was installing it in python3. After referring the document: https://docs.python.org/3/installing/index.html?highlight=pip, I could solve my problem RE: Migration of Python2 and Python3 using Modernize and Future - Gribouillis - Feb-21-2022 Rakshan Wrote:Since it is not backward compatible, it is suggested that Modernize and Futurize are betterUnless you have a very good reason to do so, trying to be backward compatible is a strange idea. If you want to migrate to Python 3, dive into it ! Trying to write code that works both for Python 2 and 3 looks harmful to this aim. It will produce heavier and lower quality Python 3 code. Just my two cents... RE: Migration of Python2 and Python3 using Modernize and Future - zuri - Oct-05-2023 hi Rakshan i tried to upgrade my code using the pip 2to3 function but it does not seems to be working can you guide me on how to use modernize and futurize functions. |