Fixing the Python subprocess interface
amoffat.github.com
Fixing the Python subprocess interface
1–10 of 65 posts
Re: Fixing the Python subprocess interface
#2Perhaps the commands should accessible from an object you import. That's slightly more typing but more explicit and would not require ugly magic. E.g.
from pbs import sh
print sh.ifconfig('eth')
If it's not clear, the 'sh' object could override __getattr__ or __getattribute__ and wrap commands as necessary.Re: Fixing the Python subprocess interface
#3Re: Fixing the Python subprocess interface
#4Neat but way too magical for my taste. The code to figure out what to do in the case of 'from .. import *' is particularly ugly. Perhaps the commands should accessible from an object you import. That's slightly more typing but more explicit and would not require ugly magic. E.g. from pbs import sh print sh.ifconfig('eth') If it's not clear, the 'sh' object could override __getattr__ or __getattribute__ and wrap comma…
Re: Fixing the Python subprocess interface
#5Neat but way too magical for my taste. The code to figure out what to do in the case of 'from .. import *' is particularly ugly. Perhaps the commands should accessible from an object you import. That's slightly more typing but more explicit and would not require ugly magic. E.g. from pbs import sh print sh.ifconfig('eth') If it's not clear, the 'sh' object could override __getattr__ or __getattribute__ and wrap comma…
Anything that encourages a from ... import * usage is evil irrespective of its implementation.
Re: Fixing the Python subprocess interface
#6Re: Fixing the Python subprocess interface
#7Neat but way too magical for my taste. The code to figure out what to do in the case of 'from .. import *' is particularly ugly. Perhaps the commands should accessible from an object you import. That's slightly more typing but more explicit and would not require ugly magic. E.g. from pbs import sh print sh.ifconfig('eth') If it's not clear, the 'sh' object could override __getattr__ or __getattribute__ and wrap comma…
ifconfig = pbs.Command("/path/to/ifconfig")Re: Fixing the Python subprocess interface
#8I 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.]Re: Fixing the Python subprocess interface
#9I'd feel more comfortable if it only exported one variable.