132
top 13 comments
sorted by: hot top controversial new old
[-] wasabi@feddit.de 19 points 8 months ago

python -m http.server came in handy so many times!

[-] ATLeagle@mastodon.online 8 points 8 months ago

@wasabi @learnbyexample one of my favorite super lazy ways to share a file

[-] namingthingsiseasy@programming.dev 6 points 8 months ago

I use json.tool a lot to format JSON directly in vim. Simply highlight the text you want to format and run :!python3 -m json.tool. There are probably plugins to do this too, but doing it this way is probably the simplest, unless vim has a built-in for it.

[-] sugar_in_your_tea@sh.itjust.works 3 points 8 months ago

Could probably do the same with :! jq . It's a bit shorter.

[-] namingthingsiseasy@programming.dev 3 points 8 months ago

Yeah, I knew someone was going to say that. Usually it's more likely that Python is installed than jq - especially on servers. But yes, that would definitely work too.

[-] sugar_in_your_tea@sh.itjust.works 2 points 8 months ago

Sure, I'm just not sure when I'd ever run into that. Either I'm doing it a lot and installing jq is reasonable, or I'm not allowed on the server anyway and need to copy/paste from logs.

I used to use python -m json.tool a lot, but I haven't needed to in many years.

[-] nickwitha_k@lemmy.sdf.org 5 points 8 months ago

Easier than grepping, you can just look at the standard library docs: https://docs.python.org/3/library/

[-] BatmanAoD@programming.dev 2 points 8 months ago

How is that easier? It doesn't look like it provides a list of which modules have a __name__ == "__main__" block.

[-] nickwitha_k@lemmy.sdf.org 1 points 8 months ago

No. But, it does provide a list of all stdlib libraries and those, like gzip, that are intended to be compatible with the CLI tend to have explicit documentation showing usage (ex. https://docs.python.org/3/library/gzip.html) and provides any other contextual info related to using the library.

Don't get me wrong, grepping through the code is a great way of building skills needed as a professional. Really, I have to do this kind of thing multiple times every week at work. It is, however, also worth noting that Python only uses an "honor system" for public/private functions, methods, and classes so modules having an "if name == 'main'" block doesn't necessarily mean that they are appropriate to use as CLI tools. They might be but, without documentation to back it up, it's an "at your own risk" situation.

[-] sugar_in_your_tea@sh.itjust.works 3 points 8 months ago* (last edited 8 months ago)

Pro tip: you can ignore filenames with ripgrep using -g "!test/". That should speed things up a bit.

[-] moonpiedumplings@programming.dev 2 points 8 months ago

python -m http.server has been a very useful tool to me, to test if a server is accessible.

[-] NotAtWork@startrek.website 2 points 8 months ago* (last edited 8 months ago)

CLITools can be hard to find, but when you do it's worth the effort.

[-] floppingfish@kbin.social 2 points 8 months ago
this post was submitted on 18 Feb 2024
132 points (98.5% liked)

Python

6343 readers
10 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS