[Python-3000] os.popen versus subprocess.Popen
Martin (gzlist)
gzlist at googlemail.com
Tue Apr 22 21:42:33 CEST 2008
On 22/04/2008, Facundo Batista <facundobatista at gmail.com> wrote:
> 2008/4/22, Andrew McNabb <amcnabb at mcnabbs.org>:
>
>
> > That's the best thing about subprocess. Whenever I've used APIs that
> > accept a single string instead of list of arguments, I've quickly
> > descended into quoting hell.
>
>
> I don't understand why, could you please provide me one example or two?
>
> Thank you!
>
>
> --
> . Facundo
Well, here's a real method I ran into a while back - with
.replace(origname, 'example'). Written by a perfectly able python
programmer in publicly released code:
def example_command(self, command, args):
args = ' '.join("'%s'" % arg for arg in args)
return 'example --example-dir=%s %s %s' % (self.example_dir, command, args)
What's wrong with it? Well, if you use unix, with no spaces in
directories and legal 'quote', you'll probably say "nothing". String
interpolating command calls makes for unnecessarily non-portable code.
Now, if subprocess could only start (optionally) taking unicode
arguments so I could actually get at my whole filesystem through it...
Martin
More information about the Python-3000
mailing list