Hi all,
-- when I try to read a file which actual encoding is gbk.
I get exception as below:
------
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 675, in readline
return self.reader.readline(size)
UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 0-1: illegal multibyte sequence
------
here is my code:
------
>>> import codecs
>>> f = codecs.open('namelist.txt',encoding='gb2312')
>>> f.readline()
------
Data example:
------
曹星 iamcaoyuxin
------
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment