[Tutor] Easier way to use 2to3?

Ken Green beachkidken at gmail.com
Fri Aug 23 20:49:20 EDT 2019


It took me a while to figure out how to do a 2to3
as shown in several examples I seen, to wit: While
in command line mode of my Ubuntu 18.04, I did the
following in a separate directory.

Python 2 program:

# sample.py

print "What a wonderful day in my neighborhood."
print
print "Yes, it is a wonderful day."

Resulted in:

What a wonderful day in my neighborhood.

Yes, it is a wonderful day.

------------------
(program exited with code: 0)
Press return to continue

When I ran 2to3 sample.py in a Python3 directory,
I get the following:

ken at kengreen:~/Python3$ 2to3 sample.py
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored sample.py
--- sample.py    (original)
+++ sample.py    (refactored)
@@ -1,6 +1,6 @@
  # sample.py

-print "What a wonderful day in my neighborhood."
-print
-print "Yes, it is a wonderful day."
+print("What a wonderful day in my neighborhood.")
+print()
+print("Yes, it is a wonderful day.")

RefactoringTool: Files that need to be modified:
RefactoringTool: sample.py
ken at kengreen:~/Python3$

Huh, what? The original program was not changed! I was
expecting a changed Python2 program to be compatible with
Python3. I ended up making the needed changes line-by-line
to my original program. What gives?

Changing all of my Python2 programs to be compatible with
Python3 will be a headache and it would take into next year
to change all. Is there a easier way?

On a side note, I have been using Geany v1.32 and it is linked
to all of my Python2. To linked to Python3, I have to use Idle
instead of Geany as it can only be linked to one Python directory
at a time.

Thanking this group in advance for any possible solution, thanks.

Ken




More information about the Tutor mailing list