On Oct 30, 12:47 pm, "thebjorn" <[EMAIL PROTECTED]> wrote: > Sachin Punjabi wrote: > > I wanted to read a file encoded in utf-8 and and using the following > > syntax in my source which throws me an error specifying Lookuperror : > > unknown encoding : utf-8. Also I am working on Python version 2.4.1.You > > shouldn't have to do anything to have the utf-8 encoding available. > Check in your lib/encodings directory for a file name utf_8.py and the > code in __init__.py in the same directory should take care of the > mapping. This has been this way since at least Python 2.2 (which is the > oldest version I have on this machine). > > If that doesn't give you a clue as to what is going on in your setup, > try > > u'foo'.encode('utf-8') > > at the prompt and post the complete traceback. > > > import codecs > > fileObj = codecs.open( "data.txt", "r", "utf-8" )That should work fine, > > although I prefer to explicitly set the mode to > "rb" (it will be set to binary mode behind your back regardless ;-) > > hth, > -- bjorn
I tried with the code you specified on the command line and it works very much fine. Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> u'foo'.encode('utf-8') 'foo' >>> Sachin. -- http://mail.python.org/mailman/listinfo/python-list