Note the question has changed over the years - please see Janus's response to get the "human" numbers or keep reading if you just want to format the number as a string with separators.
With Python2.7+ or v3 you just use the "," option in your string formatting - see PEP 378: Format Specifier for Thousands Separator for more info:
>>> "{:,}".format(100000000)
'100,000,000'
With Python3.6+ you can also use the "_" format - see PEP 515 for details:
>>> "{:_}".format(100000000)
'100_000_000'
or you can use a similar syntax with f-strings:
>>> number = 100000000
>>>f"{number:,}"
'100,000,000'
So I don't have to squint while reading big numbers, I have the 2.7 version of the code wrapped up in a shell function:
human_readable_numbers () {
python2.7 -c "print('{:,}').format($1)"
}
Lastly, if for some reason you must work with code from Python versions 2.6 or earlier, you can solve the problem using the locale
standard library module:
import locale
locale.setlocale(locale.LC_ALL, 'en_US')
locale.format('%d', 2**32, grouping=True) # returns '4,294,967,296'