Live data from Hacker News

CLI tools hidden in the Python standard library

til.simonwillison.net

1–10 of 160 posts

Re: CLI tools hidden in the Python standard library

#2
Its notable, perhaps, that the

  if __name__ == "__main__":
block allows you to do this for a _module_, i.e. a single *.py file. If you want to do this for a package, add a `__main__.py`

You can also use either of these throughout your code so that you can have

  python -m foo
  python -m foo.bar
  python -m foo.bar.baz
each doing different, but hopefully somewhat related, things.

Re: CLI tools hidden in the Python standard library

#6

python -m json.tool seems neat. I am always dumping JSON in single log lines and then expanding it to diff it (currently using Cmd+Opt+L in PyCharm).

I tend to use "jq .".

An extra tool, but you don't really have to learn it, and if you're "always dumping JSON" and also use the command line a lot, you probably want to have it around anyway.

Re: CLI tools hidden in the Python standard library

#8

I use http.server all the time, particularly as modern browsers disable a bunch of functionality if you open file URLs. Had no idea there was so much other stuff here!

Same here, it's also by far the most convenient way I've found to share files between devices on my network.

Re: CLI tools hidden in the Python standard library

#9
post #8

I use http.server all the time, particularly as modern browsers disable a bunch of functionality if you open file URLs. Had no idea there was so much other stuff here!

Same here, it's also by far the most convenient way I've found to share files between devices on my network.

Same for me. Although I just discovered `qrcp` which has been quite handy, and I'm sure there are many tools like it.
Post reply on HN