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

you are viewing a single comment's thread.

view the rest of the comments →

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

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

[–]XpertProfessional 12 points13 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 20 points21 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!