Live data from Hacker News

CLI tools hidden in the Python standard library

til.simonwillison.net

61–70 of 160 posts

Re: CLI tools hidden in the Python standard library

#61
post #55
post #50

Earlier quoted context omitted.

Do you have an example snippet you could share?

You just start an http server with python3 -m http.server 8080 and then access the server on the receiving device through its IP address. It’ll show a basic directory listing, and you can download from there.

Thanks! Very helpful.

Re: CLI tools hidden in the Python standard library

#62
post #38

Earlier quoted context omitted.

There's no magic, only layers. `python -m pdb ` runs pdb with the rest of the arguments. pdb handles the second `-m`. If you have a fancy IDE feature, open a new python file, type "import pdb", use go to definition on pdb to jump to that file in the standard library, and read its main function - it handles -m explicitly :)

Speaking of pdb.. maybe someone knows why pdb has some issues with scope in its REPL that are resolved in VSCode's debugger and PyCharm? Multiline statements are not accepted, nor things like if/for Even list comprehensions and lambda expressions have trouble loading local variables defined via the REPL Are there workarounds? It would reduce the need for using IDEs. People who have experience with Julia and Matlab ar…

There are not workaround, pdb is a rustic tool.

Since I still enjoy a cmdline debugger more than a graphical one, I use ipdb, which doesn't suffer from the multiline limitation.

However, scoping issues with lambda and comprehension are actually a Python problem, not a pdb problem.

Re: CLI tools hidden in the Python standard library

#63
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

> They regret including most modules… it seems they regret making python altogether instead of sticking with C? :D

I also find it odd. Python would probably be a little known language without the huge batteries included by default. It's invaluable when you're working in a environment where you can't fully control what is installed, what is the case of most people at work. I believe this crusade endangers the language long-term.

Re: CLI tools hidden in the Python standard library

#64
post #48
post #8

Earlier quoted context omitted.

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.

Have you checked the full docs? Maybe it takes an optional parameter to specify the server machine's IP address or host name. Then others on the network could see it.

Not near a PC now.

Re: CLI tools hidden in the Python standard library

#65
post #48
post #8

Earlier quoted context omitted.

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.

I think you must have misread the documentation [1], which says: "By default, the server binds itself to all interfaces."

[1] https://docs.python.org/3/library/http.server.html

Re: CLI tools hidden in the Python standard library

#66
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 quite an oversimplification. Some modules have no active maintainers and take time from the small team that work on CPython. Some modules are deprecated and removed to make it possible to allocate time on other improvements, and they went back on some removals when users came forward showing that they were still needed.

There is some discussion about the rationale at https://peps.python.org/pep-0594/#rationale

Re: CLI tools hidden in the Python standard library

#68
I am not someone who complains about "stop piping cats" but using '-e' with grep is a lot quicker and easier to read. This:

    grep -v 'test/' | grep -v 'tests/' | grep -v idlelib | grep -v turtledemo
Becomes:

    grep -ve 'test/' -e 'tests/' -e idlelib -e turtledemo

Re: CLI tools hidden in the Python standard library

#69
post #48
post #8

Earlier quoted context omitted.

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.

If you serve on localhost you can usually access from other devices by using the "servers" ip address. So if your desktop where you're running the server has ip 192.168.1.10 then you can go to http://192.168.1.10 in the browser of another device on the same network.

Re: CLI tools hidden in the Python standard library

#70
post #69
post #48

Earlier quoted context omitted.

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.

If you serve on localhost you can usually access from other devices by using the "servers" ip address. So if your desktop where you're running the server has ip 192.168.1.10 then you can go to http://192.168.1.10 in the browser of another device on the same network.

Ohh, that makes complete sense… thanks for pointing this out!
Post reply on HN