module documentation

Formatting varied types of values into text, (and sometimes parsing the same), mostly for readability

Function kmgtp Makes more easily skimmable sizes, e.g. :
Function url_basename Give the base filename in an URL - os.path.basename( urllib.parse.urlparse(url).path )
def kmgtp(amount, kilo=1000, append='', thresh=15, nextup=0.9, rstrip0=True, extradigits=0, i_for_1024=True):

Makes more easily skimmable sizes, e.g. :

     kmgtp(3429873278462) == '3.4T'
     kmgtp(342987327)     == '343M'
     kmgtp(34298)         == '34K'

     '%sB'%kmgtp(2342342324)                           == '2.3GB'
     '%sB'%kmgtp(2342342324, kilo=1024)                == '2.2GiB'
     '%sB'%kmgtp(2342342324, kilo=1024, extradigits=1) == '2.18GiB'
     '%sB'%kmgtp(19342342324, kilo=1024)                == '18GiB'
     '%sB'%kmgtp(19342342324, kilo=1024, extradigits=1) == '18GiB'  (because of rstrip0)
Parameters
amountthe number to summarize
kiloUses decimal/SI kilos by default, so useful beyond bytes. Specify kilo=1024 if you want binary kilos, as still frequently used for storage sizes. By default this also adds the i.
appendis mostly meant for optional space between number and unit you add yourself
threshis the controls where (in terms of the number we show) we take one digit away, e.g. for 1.3GB but 16GB. Default is at 15, which is entirely arbitrary. Disable using None.
nextupmakes us switch to the next higher up earlier, e.g. 700GB but 0.96TB Disable this behaviour by passing in None.
rstrip0whether to take off '.0' if present (defaults to true)
extradigitslets you (unconditionally) see a less-rounded number with 1 or sometimes more. (though note rstrip can still apply)
i_for_1024whether to add an i if kilo==1024
def url_basename(url):

Give the base filename in an URL - os.path.basename( urllib.parse.urlparse(url).path )

Mostly meant to show a shorter-but-not-necessarily-unique name Yes, this is a filesystemy thing to do to something that isn't, but it can be quite useful.

Yes, basename(url) will often work - except if there's query parameters.

Parameters
urlurl, as a string
Returns
base name, as a string