Neither __str__ nor __repr__ have any round-trip guarantee/expectation (they're not suitable for serialization/deserialization // marshal/unmarshal / dump/load).
Monkeypatching the __str__ or __repr__ of a builtin is generally undesirable because that's global and not thread safe.
Could you use the locale module for this number formatting regional preference (inf as unicode inf)?
LC_INFINITY=unicode
> Locale category for formatting numbers. The functions format(), atoi(), atof() and str() of the locale module are affected by that category. All other numeric formatting operations are not affected.
```quote
* Does it always just read LC_ALL='utf8' (or where do I specify that global/thread/frame-local?)
[...]
Jinja2 uses MarkupSafe, with a class named Markup:
class Markup():
def __html__()
def __html_format__()
IPython can display objects with _repr_fmt_() callables,
which TBH I prefer because it's not name mangled
and so more easily testable. [3,4]
Existing IPython rich display methods [5,6,7,8]
_mime_map = dict(
_repr_png_="image/png",
_repr_jpeg_="image/jpeg",
_repr_svg_="image/svg+xml",
_repr_html_="text/html",
_repr_json_="application/json",
_repr_javascript_="application/javascript",
)
# _repr_latex_ = "text/latex"
# _repr_retina_ = "image/png"
Suggested IPython methods
- [ ] _repr_shell_
- [ ] single_quote_shell_escape
- [ ] double_quote_shell_escape
- [ ] _repr_sql_ (*NOTE: SQL variants, otherworldly-escaping dependency / newb errors)
[1]
https://pypi.python.org/pypi/MarkupSafe[2]
https://github.com/mitsuhiko/markupsafe[3]
https://ipython.org/ipython-doc/dev/config/integrating.html[4]
https://ipython.org/ipython-doc/dev/config/integrating.html#rich-display[5]
https://github.com/ipython/ipython/blob/master/IPython/utils/capture.py[6]
https://github.com/ipython/ipython/blob/master/IPython/utils/tests/test_capture.py[7]
https://github.com/ipython/ipython/blob/master/IPython/core/display.py[8]
https://github.com/ipython/ipython/blob/master/IPython/core/tests/test_display.py* IPython: _repr_fmt_()
* MarkupSafe: __html__()
```