I used the 2to3.py script to convert several of my files to Python 3 a while back. I believe I need to run all fixers, so my command included
-f all -f buffer -f idioms -f set_literal -f ws_comma -w
I tried to run my converted code with Python 3, but got an error
[Errno 22] Invalid argument
on the line
stream.seek(-2,1)
stream is a StringIO object that is being used to parse a file. Is this a known difference in Python 2 and 3, so should I use different methods/syntax? Or is the issue in the 2to3 conversion - perhaps I didn't run the tool correctly. (I mean to run as many fixers as possible)
I don't know for sure, but I'm guessing this is a casualty of the new Unicode handling in 3.x:
However, you can use binary I/O to do this:
BTW, 3to2 is more effective than 2to3 if you want to maintain a dual codebase for a while. Also, many people (including me) are having luck maintaining a single codebase that runs on 2.x and 3.x, rather than using 2to3 or 3to2.
Here's a link to a presentation I gave about writing code to run on 2.x and 3.x: http://stromberg.dnsalias.org/~dstromberg/Intro-to-Python/
PS: Analogous to StringIO, is BytesIO: