CLI tools hidden in the Python standard library
til.simonwillison.net
CLI tools hidden in the Python standard library
1–10 of 160 posts
Re: CLI tools hidden in the Python standard library
#2 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
#3Re: CLI tools hidden in the Python standard library
#4I 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!
www='python -m http.server'
Re: CLI tools hidden in the Python standard library
#5Re: CLI tools hidden in the Python standard library
#6python -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).
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
#7python -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).
Re: CLI tools hidden in the Python standard library
#8I 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!
Re: CLI tools hidden in the Python standard library
#9I 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
#10Using modules (even if they are in the standard library) on the command line lets malicious code in the current dir take over your machine: