Unicode support

R

Richy2004

I've experienced problems when trying to load a text file encoded with
2byte unicode characters. No matter what combination of the following
I try, I always get an error when
executing file.readline()

file = open("file.txt", "r")
file = open("file.txt", "rb")
file = codecs.open("file.txt", "rb", "utf-16")
file = unicode(open("file.txt", "r"), "utf-16")

Even more strangely it does work when used in the interactive
interpreter.

Any ideas?

Thanks,
Richard
 
P

Peter Hansen

Richy2004 said:
I've experienced problems when trying to load a text file encoded with
2byte unicode characters. No matter what combination of the following
I try, I always get an error when
executing file.readline()

file = open("file.txt", "r")
file = open("file.txt", "rb")
file = codecs.open("file.txt", "rb", "utf-16")
file = unicode(open("file.txt", "r"), "utf-16")

Even more strangely it does work when used in the interactive
interpreter.

Any ideas?

Always post the actual traceback (cut and pasted from another window)
when saying you are getting an error. That avoids lots of guessing
on our part as to what is going on.

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,666
Latest member
selsetu

Latest Threads

Top