[Tutor] Read in text file containing non-English characters

Walter Prins wprins at gmail.com
Fri Jan 13 23:30:12 CET 2012


Hi Francis,

On 13 January 2012 14:52, Francis P. Boscoe <fpb01 at health.state.ny.us> wrote:
>> I apologize for not including any code, but that's because I didn't have any. I had no idea where to even begin. I have a 450 page book on beginner Python programming and nothing like the above is in >there. Incidentally, when I try the above code in Python 3.2 I get an "invalid syntax" message.

As mentioned by Martin, the reason you get a syntax error is because
the print statement doesn't exist anymore in Python 3.x --  It's been
replaced with a print() function to make it more consistent with the
rest of the language.

That said, please be aware that there's many changes between Python
2.x and 3.x, even though they look and act more similar than not.
Nevertheless you should be aware of which major version you're using
and make adjustments accordingly.  As of right now, unless you have
particular reason to do so, I'd say stick with Python 2.7 and only
switch to Python 3.2 or better once you have a handle on the basics on
unless you have a specific reason to go with 3.x. However, one of the
big differences as mention before between Python 2.x and 3.x is
Unicode handling so this might be one reason for you to actually have
a more serious look at Python 3.x despite what I've just suggested...

Also, for reference, the following presentation which discusses
differences between Python 2 and Python 3 from an I/O p.o.v. but also
comments quite a bit on the Unicode changes (Unicode has a direct
impact on text I/O) and related subtleties that might bight one if
you're not careful:
http://www.slideshare.net/dabeaz/mastering-python-3-io-version-2

HTH,

Walter


More information about the Tutor mailing list