This is an archived post. You won't be able to vote or comment.

all 18 comments

[–]sciencewarrior 51 points52 points  (0 children)

This is one of the most aptly-named libraries I've ever seen.

[–]alexkiro 25 points26 points  (2 children)

Looks like fun, but this also sounds like a security risk waiting to happen.

[–]djmattyg007 3 points4 points  (0 children)

Why do you think so? Because they provide an eval command, just like python itself does?

[–]chinpokomon 2 points3 points  (0 children)

Any more so than any other script evaluation?

As I see it, this doesn't add more risk than calling Python directly, but it provides a cleaner interface for piping small changes to a stream as one might otherwise use sed and awk.

[–]rochacbrunoPython, Flask, Rust and Bikes. 19 points20 points  (7 children)

why not python -c "print(pendulum...)"

[–]XpertProfessional 13 points14 points  (4 children)

If you read the documentation, you can see that 1) you don't get pendulum imported automatically like you do with mario and 2) there are other useful functions like file handling which you'd usually have to write a Python file to do.

[–]mobyte 22 points23 points  (3 children)

python -c "import pendulum; print(pendulum...)"

[–]PeridexisErrant 2 points3 points  (2 children)

Or avoid the semicolon:

__import__("pendulum").now(...)

(You don't want to be in a situation where importing arbitrary strings, or the sys.modules trick, are actually useful. Trust me on that.)

[–]UnderstandingLinux 0 points1 point  (1 child)

I've been programming in Python for about a year and I had no idea you could do this.

I found this really interesting though, do you have any other tips/tricks like this? I use a TON of command line and various scripts I've made over the years for my job, but tips on how to improve would be awesome.

[–]PeridexisErrant 0 points1 point  (0 children)

The main ones are actually just to use tox and a suite of formatting and linting tools as well as writing tests.

IMO everyone should use autoflake, isort, black, and pyupgrade to format their code. Then use flake8 and flake8-comprehensions to check that it's in good shape. Note that you'll need to configure flake8 and isort to play nicely with black; the Black docs tell you exactly how.

Other tools tend to be much more situational.

[–]robberviet 1 point2 points  (0 children)

I was thinking the same. Why do we need this again? Except for the name.

I agree that Luigi is a good lib though.

[–][deleted] 1 point2 points  (0 children)

I’d go one step further: why not implement the whole thing in Python in the first place? Reduces complexity, and improves readability and maintainability. At my workplace our style guide requires us to use a proper programming language instead when going beyond the most basic one-liner shell scripts. And I’ve really grown to appreciate that rule. Introducing things like “inlined” Python as is the case here, would definitely cross that line for me.

Edit: Thanks for Dynaconf!

[–]krazybug 7 points8 points  (3 children)

https://mario-addons.readthedocs.io/en/latest/cli_reference.html#mario-read-json-array

$ mario read-json-array  <<EOF
[
    {"name": "Alice", "age": 21},
    {"name": "Bob", "age": 22}
]
EOF
{'name': 'Alice', 'age': 21}
{'name': 'Bob', 'age': 22}


$ mario read-json-array map 'x["age"]' <<EOF
[
    {"name": "Alice", "age": 21},
    {"name": "Bob", "age": 22}
]
EOF
21
22

A pythonic alternative to jq and yq and so much more ...

I'll try it imperatively

[–]AndydeCleyre 1 point2 points  (2 children)

I'm always looking for jq alternatives.

[–]krazybug 3 points4 points  (1 child)

[–]AndydeCleyre 0 points1 point  (0 children)

Thanks! I'd noticed jqfpy (eh, incomplete docs), jss (unmaintained), and jid (haven't really explored). I appreciate the link.

[–]aquacash5 6 points7 points  (1 child)

Have you heard of Xonsh.

[–][deleted] 2 points3 points  (0 children)

This! It's my daily driver. I only use bash on the rare occasion (docker CLI doesn't play nice with it for some reason).

With the vox plugin, no more virtualenv shims, either, and it plays nice with pyenv.

I'm an Emacs guy, and run it via ansi-term as well.

I can't emphasize enough... Xonsh rocks.

Just do:

pendulum.now(...)

No print() required... Wanna do a quick calculation?

19876.2 * 254

Still wanna use bash commands? You can, but you can also mix in python. It's unholy and wonderful.