top | item 37414109

(no title)

MassiveBonk51 | 2 years ago

Why does it have to be bash+python? I'm finding myself using node.js scripts glued together by bash ones these days unless I'm working on a lot of data. Doing that means you can work with json natively.

discuss

order

rtpg|2 years ago

`json.loads` in Python exists, and Python does the intuitive thing when you do `{"a": 1} == {"a": 1}`, at least for most purposes (you want the other option? `is` is right there!). Stuff like argparse is not the easiest thing to use but it's in the standard library and relatively easy to use as well.

Not going to outright say that node.js scripts are the worst thing ever (they're not), but out-of-the-box Python is totally underrated (except on MacOS where `urllib` fails with some opaque errors untill you run some random script to deal with certs)

peferron|2 years ago

I haven't had a great experience dealing with JSON in Python, but maybe I'm doing it wrong. What would be the Python equivalent of this JS code?

    JSON.parse(<data>).foo?.[0]?.bar
Basically just return the `bar` field of the the first element of `foo`, or None/undefined if it doesn't exist.

claytongulick|2 years ago

I love nodejs, it's my go-to language for server side stuff.

Even with that bias though, I have to admit that it's awful for typical command line script stuff.

Dealing with async and streams and stuff for parsing csv files is miserable (I just wrote some stuff to parse and process hundreds of gigs of files in node, and it wasn't fun).

Python is the right tool for that job IMHO.

Also, weirdly, maybe golang? I just came across this [1] and it has one of my eyebrows cocked.

[1] https://bitfieldconsulting.com/golang/scripting

avarun|2 years ago

Ruby is the clear answer here. The fact that more people don't use it for this purpose (its intended purpose!) is a travesty.

majkinetor|2 years ago

Any not-designed-specifically-for-shell language will suck for shell, more or less. Ruby, python, node, whatever, they all have the same problem - you write stuff too much and care about stuff you shouldn't care while in shell.

MassiveBonk51|2 years ago

You're probably right. I just wish there was an easier way to handle json on the command line that didn't turn into its own dsl. The golang scripting seems interesting, might be what motivates me to learn the language.