Encoding for Devanagari Script.
mail at timgolden.me.uk
Mon Jul 28 17:56:58 CEST 2008
> Hi Fredrik and Terry,
> Well I got this on IDLE I think I have done something wrong.
>>>> import codecs
>>>> f = open("C:\Documents and Settings\admin\My Documents\corpus\dainaikAikya collected by sushant.txt","r", "utf_8")
> Traceback (most recent call last):
> File "<pyshell#1>", line 1, in <module>
> f = open("C:\Documents and Settings\admin\My Documents\corpus
> \dainaikAikya collected by sushant.txt","r", "utf_8")
> TypeError: an integer is required
> PS: the above code I wrote using the information from the Library
> Reference pdf section 4.8 "Codecs". Something wrong I am doing? Please
> do let me know.
Only slightly. You're importing the codecs module
but you're not using it. So you're *actually* using
the built-in open function, which doesn't have an
encoding parameter. It does have a third param
which is to do with the buffer size.
Just change your code to use codecs.open ("...")
and, I suggest, either use raw strings for your
filename (r"c:\docume...") or use the other kind
of slash ("c:/documen..."). Otherwise you might
run into some problems.
More information about the Python-list