相关疑难解决方法(0)

Using Python textwrap.shorten for string but with bytes width

I'd like to shorten a string using textwrap.shorten or a function like it. The string can potentially have non-ASCII characters. What's special here is that the maximal width is for the bytes encoding of the string. This problem is motivated by the fact that several database column definitions and some message buses have a bytes based max length.

For example:

>>> import textwrap
>>> s = '? Ilsa, le méchant ? ? gardien ?'

# Available function that I …
Run Code Online (Sandbox Code Playgroud)

python word-wrap

6
推荐指数
1
解决办法
416
查看次数

标签 统计

python ×1

word-wrap ×1