Live data from Hacker News

CLI tools hidden in the Python standard library

til.simonwillison.net

41–50 of 160 posts

Re: CLI tools hidden in the Python standard library

#41
post #39
post #23

Earlier quoted context omitted.

It seems like the discussion of whether to document it died in April of 2003: https://mail.python.org/pipermail/python-dev/2003-April/0350... Bummer, it's a cool feature, but I don't feel safe relying on undocumented features.

Especially now that they are on a crusade against their own stdlib. They regret including most modules… it seems they regret making python altogether instead of sticking with C? :D

This is a typical programmer, you'll regret code as soon as you turn your back on it. :)

Re: CLI tools hidden in the Python standard library

#42
post #22

Speaking of hidden Python tools, I'm a big fan of re.Scanner[0]. It's a regex-based tokenizer[1] in the `re` module, that for reasons is completely missing from any official documentation. You give it a pattern for each token type, and a function to be called on each match, and you get back a list of processed tokens. Importantly, it processes the list in one pass and ensures the matches are contiguous, where a naive…

FWIW there is an example of building a tokenizer/scanner using documented features of the re module here: https://docs.python.org/3.11/library/re.html#writing-a-token...

re.Scanner looks more succinct though...!

Re: CLI tools hidden in the Python standard library

#43

Python 3.12 will include a SQLite CLI/REPL in the standard library too[0][1]. This is useful because most operating systems have sqlite3 and python3, but are missing the SQLite CLI. [0]: https://github.com/python/cpython/blob/3fb7c608e5764559a718c... [1]: https://docs.python.org/3.12/library/sqlite3.html#command-li...

> This is useful because most operating systems have sqlite3 and python3, but are missing the SQLite CLI. Not sure what you mean -- sqlite3 is the SQLite CLI.

Yes, I meant the DLL/.so file. The library is almost always present in the OS, the CLI is not.

Re: CLI tools hidden in the Python standard library

#45

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!

Chrome also often takes forever to load even the simple HTMLs if it's a local file.

I suspect it's related to relative path resource but never figured it out.

Re: CLI tools hidden in the Python standard library

#46
post #19

Earlier quoted context omitted.

You don't need the `.` fwiw, just `produce-compact-json | jq` will do.

Not always, some versions of jq get confused without the dot. I work on two Linuces at work, one requires it and one doesn't.

The current version and for quite some time, then.

If I said 'Windows comes with the Edge browser' would you say 'I use two at work, one does but the other only has Internet Explorer'? Surely it's generally implied we're talking about things as they are, unless specified otherwise?

Re: CLI tools hidden in the Python standard library

#47
post #22

Speaking of hidden Python tools, I'm a big fan of re.Scanner[0]. It's a regex-based tokenizer[1] in the `re` module, that for reasons is completely missing from any official documentation. You give it a pattern for each token type, and a function to be called on each match, and you get back a list of processed tokens. Importantly, it processes the list in one pass and ensures the matches are contiguous, where a naive…

This is one of the best ChatGPT use cases: creating regex complex patterns

Re: CLI tools hidden in the Python standard library

#48
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.

Wait, how does that work? As far as I can see from the documentation, it can only serve on localhost, which to my understanding is only accessible from the single device it was launched on.

Re: CLI tools hidden in the Python standard library

#49
post #25

> Pretty-print JSON: > echo '{"foo": "bar", "baz": [1, 2, 3]}' | python -m json.tool This is even more fun on MacOS if you combine it with the pbpaste/pbcopy utils: alias json_pretty="pbpaste | python -m json.tool | pbcopy" That command will pretty-print any JSON in your clipboard, and write it back to the clipboard, so you can paste it somewhere else formatted!

    alias json-format="python -m json.tool | pygmentize -l javascript"
Post reply on HN