3 ms·
It's odd that the import mechanism is abused here to make objects "out of thin air". The fact that "from pbs import ffmpeg" works only if ffmpeg is actually on
by samps 15y ago
It's odd that the import mechanism is abused here to make objects "out of thin air". The fact that "from pbs import ffmpeg" works only if ffmpeg is actually on the path is somewhat surprising.
I think the more comfortable (and Pythonic?) way to do this would be to explicitly create these command objects:
>>> import pbs
>>> ffmpeg = pbs.Command('ffmpeg') # or '/usr/bin/ffmpeg', perhaps
>>> result = ffmpeg(...)
[Edit: I really like the concept of using Python's positional and keyword arguments to construct a shell command, though. Great insight there.]
- SoftwareMaven 15y agoExcept that changes what it is trying to accomplish. The goal (as I read it) is to make shell scripting more palatable in python. Needing to continually differentiate between "this is python" and "this is system" gets old very fast. In your example, what pbs is doing is no different than a bash shell script reporting a "command not found". It isn't what I would want if I were writing a complex piece of software interacting with ffmpeg, but for a simple script to process a bunch of files in a directory, I like it. I've tended to shy away from using Python for shell scripting because subprocess is so ugly (even its out-of-favor, crippled relative os.system is nasty), and pbs looks like it does a really great job at addressing that.
- samps 15y agoAgreed. As a way to write one-off scripts that one would otherwise use bash for, this seems like a nice trick.
- daenz 15y agoHi! Author here, there are a few ways to use it, including your suggestion (did you make your suggestion up or were you pulling from the docs?): # magical, designed only for single shell scripts from pbs import * ffmpeg() # less magical from pbs import ffmpeg ffmpeg() # or import pbs pbs.ffmpeg() # no magic import pbs ffmpeg = pbs.Command(pbs.which("ffmpeg")) # command takes full path ffmpeg() I tried to cover the main use cases adequately. My goal was to ease a pain point myself and others have experienced, that other popular packages don't address well unfortunately. If it's helped anyone like it's helped me, I'm happy and glad to share!
- tingletech 15y agoThis looks really cool. It was not clear to me on the first reading of the document that it could be invoked these ways. The pbs.Command() example is way down in the "weird filenames" part. I just did a quick change to the README and sent you a pull request.
- samps 15y agoWow -- no, I entirely missed this (and just happened to end up with the same name). Thanks for clarifying.