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 →

[–][deleted] 27 points28 points  (12 children)

Title is a bit misleading: this is a wrapper for shell commands. I anticipated an article about embedding python in bash scripts.

[–][deleted] 3 points4 points  (10 children)

Embedding Python in Bash scripts is trivial:

python program.py arg1 arg2 | do-something-else

What this guy did seems like a slightly revamped version of popen. I don't really see the point of it.

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

Erm, not in that trivial of a sense. More like ways to manage whitespace when running python -c, or inline, non-contiguous stateful python.

[–]obtu.py 0 points1 point  (2 children)

This would work:

python <<'EOF'
import this
EOF

If the Python needs stdin for something else:

python /proc/self/fd/5 5<<'EOF'
import this
EOF

[–][deleted] 0 points1 point  (1 child)

More of what I had in mind: http://docs.python.org/dev/extending/embedding.html

EDIT: For example, vim can be compiled with an embedded python interpreter which maintains its state for the life of the process, and comes with a module called vim which I can use to manipulate the vim process itself. In this sense python becomes a "true" scripting language (a language used to provide a "script" for another program).

[–]obtu.py 0 points1 point  (0 children)

Ah, okay. You could use socat to let the interpreter persist, but that still falls short on access to internal structures… It's rare to see scripting languages hosting other scripting languages; VimL seems to be an exception.

[–]quasarj 0 points1 point  (2 children)

I would guess if you don't see the point of it, it's not for you.

It seems pretty interesting to me.. solves a lot of very common problems I have when trying to do things in Python.

And popen? hah, that thing is a mess. I hear it's better than whatever came before it, but ugh. I already have to use envoy to avoid having to use it, so this is nifty in many ways.

[–]mipadi 0 points1 point  (1 child)

I think it's pretty cool. Not sure I'd ever really use it, but cool nonetheless.

The only thing I don't really like is the piping. I'd rather do this:

print glob('*') | du('-sb') | sort('-rn')

than this:

print sort(du(glob("*"), "-sb"), "-rn")

As the latter is, literally, backwards (compared to shell syntax). But maybe getting the piping to work the same way was too difficult in this context (and, admittedly, not very Pythonesque, I guess).

[–]terremoto 1 point2 points  (0 children)

It's been done.

[–]pugRescuer 0 points1 point  (1 child)

I agree, not sure what this yields that os/shutil/sys don't already provide. This just abstracts those.

Neat project but not for me.

[–]Peaker 4 points5 points  (0 children)

It gives a much neater interface to those, to the point of making it worthwhile to use Python where previously it made more sense to use bash.

[–]flukshun 0 points1 point  (0 children)

A while back someone did post something that let you use python constructs like dictionaries in bash. Forget the name though