Skip to content

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.

one_milli = 1_000_000
one_billi = 1_000_000_000

You should most definitely use humanize. It’s like totally amazing.

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


share this post on:

Previous Post
Firing a million async requests with Python
Next Post
Concurrent downloads with Python using asyncio or thread pools
t>