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)