help in code

P

pahi sharma

I am new to python .I have a corpus which is written in Bengali and i
want to read that file using python code.Can anyone help me in this
matter.
Thank You
 
S

Steven D'Aprano

I am new to python .I have a corpus which is written in Bengali and i
want to read that file using python code.Can anyone help me in this
matter.

In Python 3, I believe this should work:

f = open("filename", encoding="which-encoding-you-use")
text = f.read()
f.close()


In Python 2, you probably need to do this:


f = open("filename")
bytes = f.read()
text = bytes.decode('which-encoding-you-use')
f.close()


Hope this helps.
 
U

Ulrich Eckhardt

Steven D'Aprano wrote:
[reading Bengali]
In Python 2, you probably need to do this:

f = open("filename")
bytes = f.read()
text = bytes.decode('which-encoding-you-use')
f.close()

In Python 2, I'd rather take a look at the "codecs" module (see
http://docs.python.org), namely the "codecs.open" function.

Uli
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top