Chr for non-ASCII characters in Python

I am trying to implement a string list search in a context where there is no way to use something like str.startswith (If you are interested, I refer to the application data store). I would like to find every line that has a specific prefix, let them say "py".

I have comparison operators at my disposal, so I thought I could implement this as follows.

 #pseudo code search = "py" search_strings_where(s > search, s < chr(ord(search[0]) + 1) 

It is assumed that chr(ord(search[0]) + 1) is a character that is in the lexicographic order immediately after the first character of the search query.

The problem is that this will not work. take, for example, ord(u"‰") , which returns 8240. But inserting in chr again raises an error.

 ValueError: chr() arg not in range(256) 

How can i solve this?

EDIT Just found out about unichr, checking if this works. I will write an answer, if so.

+6
source share
1 answer

Maybe use unichr () , this function will work

+19
source

All Articles