[Tutor] UnicodeEncodeError
gpo
goodpotatoes at yahoo.com
Sun Jul 19 07:34:53 CEST 2009
I'm doing a simple excercise in reading a file, and printing each line.
However, I'm getting this error. The file is a windows txt file, ecoded in
ANSI(ascii). I don't understand why Pythin is displaying a Unicode error.
Here is my script:
f=open('I:\\PythonScripts\\statement.txt')
for line in f:
print (line)
f.close()
statement.txt is just a copy of the text from an article at
(http://www.tgdaily.com/content/view/43296/98/) into notepad.
The error I get is:
Traceback (most recent call last):
File "I:\PythonScripts\fileloop.py", line 9, in
print (line)
File "C:\Python31\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2014' in
position
10: character maps to
I've looked this up, and see that others have had a similar error; however,
I don't see any thing saying what I should be encoding to/from since my
input and output files are both ascii.
--
View this message in context: http://www.nabble.com/UnicodeEncodeError-tp24554280p24554280.html
Sent from the Python - tutor mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090718/35cca89b/attachment.htm>
More information about the Tutor
mailing list