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

Francis P. Boscoe fpb01 at health.state.ny.us
Fri Jan 13 15:52:40 CET 2012










>You don't show even a snippet of code.  If you are asking
>for help here, it is good form to show us your code.  Since
>you don't state how you are reading the data and how you are
>printing the data, we can't help much.  Here are some tips:
>
>  * Consider learning how to use the csv module, particularly in
>    your case, csv.reader (as Ramit Prasad has already suggested).
>
>  * Consider checking the bytestream to see if the bytes produced
>    on output are the same as on input (also, read the text that
>    Mark Tompkins indicated and learn to distinguish Unicode from
>    UTF-8).
>
>  * Report back to the list the version of Python you are using.
>    [Different versions of Python have subtly different handling of
>    non ASCII character set data, but this should probably not be an
>    issue for the more obvious issue you are showing above.]
>
>We can have no idea what your ultimate goal is with the data, but
>can help you much more if you show us the code.
>
>Here's a sample of what I would/could do (Python 2.6.5):
>
>    import csv
>    reader = csv.reader(open('input-data.txt'),delimiter=',')
>    for row in reader:
>        print 'The capital of %s is %s' % (row[0], row[1],).
>
>The above is trivial, but if you would like some more substantive
>assistance, you should describe your problem in a bit more detail.


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.

My ultimate goal is to be able to do what I've done for years in SAS, where
I consider myself an expert: read in some raw data, perform some
mathematical operations on the data, then output it.  Later this spring I
will be teaching an audience that does not have access to SAS (community
college students) and Python was suggested as an alternative.

IMPORTANT NOTICE: This e-mail and any attachments may contain confidential or sensitive information which is, or may be, legally privileged or otherwise protected by law from further disclosure. It is intended only for the addressee. If you received this in error or from someone who was not authorized to send it to you, please do not distribute, copy or use it or any attachments. Please notify the sender immediately by reply e-mail and delete this from your system. Thank you for your cooperation. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120113/f2fc286e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20120113/f2fc286e/attachment.gif>


More information about the Tutor mailing list