dragfire
dragfire

Reputation: 443

Accessing Bangla (UTF-8) string by index in Python

I have a string in Bangla and I'm trying to access characters by index.

# -*- coding: utf-8 -*-
bstr = "তরদজ"
print bstr # This line is working fine
for i in bstr:
    print i, # question marks are printed

I don't know why it isn't working.

Upvotes: 0

Views: 1665

Answers (1)

famousgarkin
famousgarkin

Reputation: 14126

Turn it into unicode:

>>> bstr = "তরদজ"
>>> for i in bstr.decode('utf-8'):
...     print i
... 
ত
র
দ
জ

Upvotes: 3

Related Questions