New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module level tools, runnable from a CLI? #35

tbielawa opened this Issue Aug 15, 2014 · 2 comments


None yet
2 participants
Copy link

tbielawa commented Aug 15, 2014

For reference, the json library has json.tool to handle input streams. You can run it on a shell prompt to pretty print json

curl http://something.json | python -m json.tool

Wondering if there's anything useful bitmath could do like this?

$ python -m 1024

^ this would actually simplify my own personal frequent use case where I get a number in bytes printed in one shell,and I can't quite tell how big it is. Usually I'll just open another shell, import bitmath and then print out Byte(some_number).best_prefix().

@tbielawa tbielawa added this to the hack day milestone Aug 15, 2014


This comment has been minimized.

Copy link

ashcrow commented Aug 15, 2014

How about this?

$ bitmath -f MB -t GB 1000.23
$ bitmath -f Byte 100000
976.5625 KiB
$ bitmath --help
usage: bitmath [-h] -f
                   [-t {Bit,Byte,KiB,MiB,GiB,TiB,PiB,EiB,kB,MB,GB,TB,PB,EB,Kib,Mib,Gib,Tib,Pib,Eib,kb,Mb,Gb,Tb,Pb,Eb}]

Converts from one type of size to another.

positional arguments:
  size                  The number to convert.

optional arguments:
  -h, --help            show this help message and exit
  -f {Bit,Byte,KiB,MiB,GiB,TiB,PiB,EiB,kB,MB,GB,TB,PB,EB,Kib,Mib,Gib,Tib,Pib,Eib,kb,Mb,Gb,Tb,Pb,Eb}, --from {Bit,Byte,KiB,MiB,GiB,TiB,PiB,EiB,kB,MB,GB,TB,PB,EB,Kib,Mib,Gib,Tib,Pib,Eib,kb,Mb,Gb,Tb,Pb,Eb}
                        Input type you are converting from.
  -t {Bit,Byte,KiB,MiB,GiB,TiB,PiB,EiB,kB,MB,GB,TB,PB,EB,Kib,Mib,Gib,Tib,Pib,Eib,kb,Mb,Gb,Tb,Pb,Eb}, --to {Bit,Byte,KiB,MiB,GiB,TiB,PiB,EiB,kB,MB,GB,TB,PB,EB,Kib,Mib,Gib,Tib,Pib,Eib,kb,Mb,Gb,Tb,Pb,Eb}
                        Input type you are converting to. Attempts to sense
                        best result if omitted.

This comment has been minimized.

Copy link

tbielawa commented Aug 15, 2014

From IRC:

@tbielawa | 99%
@tbielawa | if Byte were the default for -f it'd be 100%
ashcrow | k
@tbielawa | so that 'bitmath 1024' would return 1 KiB
@tbielawa | that'd be so amazeballs
ashcrow | $ bitmath 1024
ashcrow | 1.0 KiB
@tbielawa | osnap
ashcrow | tbielawa: almost done
ashcrow | then I'll pull request it

@tbielawa tbielawa closed this in c5e4e3c Aug 15, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment