> I think this has potential, but it is too liberal. There are many more
> characters that cannot be assumed printable, e.g. many of the Latin-1
> characters in the range 0x80 through 0x9F. Isn't there some Unicode
> data table that shows code points that are safely printable?
As Michael Urman pointed out, we can use Unicode properties.
Or we can define a set of non-printable characters (e.g.
sys.nonprintablechars).
> OTOH there are other potential use cases where it would be nice to see
> the \u escapes, e.g. when one is concerned about sequences that print
> the same but don't have the same content (e.g. pre-normalization).
For such cases, print(s.encode("ascii", "backslashreplace")) might work.