> Plain-text rendering of a visual post, for machine consumers.
> Charts, diagrams and images are omitted; their captions are kept inline.
> Titles on collapsible asides are dropped, their contents kept.
> The complete version is at https://abhay.fyi/humanize-your-outputs-for-other-humans-with-python/

# Humanize your outputs for other humans with Python

> This shows how to humanize your outputs for other humans with Python.

- Author: Abhay Kashyap (https://abhay.fyi/#person)
- Published: 2022-10-07
- Canonical: https://abhay.fyi/humanize-your-outputs-for-other-humans-with-python/

---
First, if you have long numbers, you should maybe like add underscores or something.
Underscores are actually like totally ignored by Python but they make it easier for humans to read.

```python
one_milli = 1_000_000
one_billi = 1_000_000_000
```

You should most definitely use [`humanize`](https://python-humanize.readthedocs.io/en/latest/).
It's like totally amazing.

```python
import humanize

humanize.intcomma(1_000_000)
# '1,000,000'
humanize.intword(1_500_000_000)
# '1.5 billion'
humanize.scientific(4_600_000_000_000)
# '4.60 x 10¹²'
humanize.ordinal(22)
# '22nd'
humanize.naturalsize(8_192)
# '8.2 kB'
humanize.naturalsize(8_192, binary=True)
# '8.0 KiB'
```

---

### references

- [humanize](https://python-humanize.readthedocs.io/en/latest/)