例如我有一个字符串,我希望找到一个简单的方法来获取一个子字符串,它以utf-8编码,并且子字符串的repr的长度是<= N,当然我可以尝试N / 3个子字符串并增加N/3+1, N/3+2,...,但是有没有简单的方法呢?
word = u"this is a ship, and some other words".encode("utf-8")
#some way got a substring
substring = func(word, N)
#assert len(repr(substring)) <= N
谢谢!