Python Forum
2to3 fails on very simple script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
2to3 fails on very simple script
#1
i have this very simple script:
print()
that prints
Output:
()
but when i run 2to3 on it, it says

Output:
RefactoringTool: No files need to be modified.
D'oh!
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
It is 2 to 3, you attempt to modify 3 to what?   Wink
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
(Oct-18-2016, 10:14 AM)wavic Wrote: It is 2 to 3, you attempt to modify 3 to what?   Wink

well, he "attempts" to convert simple python 2 script that has single print statement that prints empty tuple...
I didn't try this myself, but I assume Skaperen did it right that's the result he gets. Anyway - from the docs:
Quote:Since some print statements can be parsed as function calls or statements, 2to3 cannot always read files containing the print function.
Reply
#4
(Oct-18-2016, 10:38 AM)buran Wrote: well, he "attempts" to convert simple python 2 script that has single print statement that prints empty tuple...
Hm! It looks like python3 print function to me? May be it's what you say.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
Exactly. That single line is legitimate in both python 2 (as a print statement) and in python 3 (as a print function). And the docs make it clear in this case 2to3 is not to be blamed
Reply
#6
That's already a valid python3 file. So there isn't any conversion that needs to take place.
Reply
#7
(Oct-18-2016, 03:04 PM)nilamo Wrote: That's already a valid python3 file.  So there isn't any conversion that needs to take place.

in python 2 it is a print statement that prints an empty tuple Tongue   so what if python3 can run it as-is Sick  it does something different with it (prints an empty line) Shy   no i did not read the docs of 2to3 so i was not aware of cases like this that it cannot figure out Evil   let's see if you can write python 3 code that does what this code does in python 2 (it prints an empty tuple) Confused   would you cheat and use the string '()' Huh  i might Big Grin
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#8
In 2to3 doc.

Quote:When the -p is passed, 2to3 treats print as a function instead of a statement.

You can of course also put this line in python 2.x code.
from __future__ import print_function

print()
Reply
#9
true, but that's not the challenge. the challenge is to get code that does the same thing now in python3 and keep it simple. how simple can it be done in python3?  is this the best case?
print('()')
?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#10
(Oct-19-2016, 06:51 AM)Skaperen Wrote: true, but that's not the challenge. the challenge is to get code that does the same thing now in python3 and keep it simple. how simple can it be done in python3?  is this the best case?
print('()')
?

well, I start to be confused about all this. If you want the python 3 code to print empty tuple, then it is as follows
print(())
Output:
Python 3.5.2 (default, Jul 17 2016, 00:00:00) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print (()) () >>>
I don't understand why the complications with printing the  str '()'. If you want to print empty tuple, do it...
The original questions was regarding unexpected behaviour using 2to3 tool
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple Python script, path not defined dubinaone 3 2,687 Nov-06-2021, 07:36 PM
Last Post: snippsat
  Need help creating a simple script Nonameface 12 4,516 Jul-14-2020, 02:10 PM
Last Post: BitPythoner
  Python 3.6.10 fails when running a localized script. Mikee 2 2,121 Jul-09-2020, 10:25 PM
Last Post: Mikee
  Simple text to binary python script gmills13 2 2,803 Feb-04-2020, 08:44 PM
Last Post: snippsat
  python script fails with a lot of data bluethundr 2 2,132 Nov-11-2019, 01:35 PM
Last Post: bluethundr
  Made a simple script for android (really simple) but it is not running anddontyoucomebacknomore 2 2,351 Mar-06-2019, 12:19 AM
Last Post: anddontyoucomebacknomore
  How to use 2to3.py converter under Windows OS samsonite 2 7,287 Mar-02-2019, 05:49 AM
Last Post: samsonite
  Confusing output from 2to3 about what files need change Moonwatcher 1 4,816 Dec-30-2018, 04:07 PM
Last Post: Gribouillis
  Error during 2to3 conversion krow4869 3 3,965 Oct-14-2018, 08:19 AM
Last Post: Larz60+
  Simple script that seems to misbehave? Nwb 1 2,326 Jun-10-2018, 05:30 AM
Last Post: Nwb

Forum Jump:

User Panel Messages

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