在Python中按索引访问Bangla(UTF-8)字符串

时间:2022-03-01 10:36:15

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

我在Bangla有一个字符串,我试图通过索引访问字符。

# -*- 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.

我不知道为什么它不起作用。

1 个解决方案

#1


Turn it into unicode:

把它变成unicode:

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

#1


Turn it into unicode:

把它变成unicode:

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