Not sure if this is exactly the problem, but I'm trying to insert a tag in the first letter of a Unicode string, and it seems like this doesn't work. Could this be because Unicode indexes work differently than regular strings?
Now my code is:
for index, paragraph in enumerate(intro[2:-2]):
intro[index] = bold_letters(paragraph, 1)
def bold_letters(string, index):
return "<b>"+string[0]+"</b>"+string[index:]
And I get the output as follows:
<b>?</b>?רך האחד וישתבח הבורא בחכמתו ורצונו כל צבא השמים ארץ וימים אלה ואלונים.
Unicode seems to be messed up when I try to insert an HTML tag. I tried messing with the insertion position, but made no progress.
An example of the desired conclusion (Hebrew goes from right to left):
>>>first_letter_bold("הקדמה")
"הקדמ<\b>ה<b>"
By the way, this is for Python 2
source
share