On Tue, Apr 22, 2008 at 03:33:30PM -0300, Facundo Batista wrote: > 2008/4/22, Andrew McNabb <[EMAIL PROTECTED]>: > > > 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?
Here's a really simple example:
("bash", "-c", 'FILE="/tmp/a b c"; cat "$FILE"')
That's pretty simple as a list of arguments. But if you do it as a
single string, you get:
'bash -c \'FILE="/tmp/a b c"; cat "$FILE"\''
It can get much worse than this, especially if you need to use
backslashes.
Here's another argument that you might find even more convincing. What
if you got a filename from a user, and had to pass that filename as an
argument to a command. If your argument was a string, like:
"cat %s" % filename
then your program would break if filename contained spaces. However, if
your arguments are
("cat", filename)
then everything does exactly what you expect.
--
Andrew McNabb
http://www.mcnabbs.org/andrew/
PGP Fingerprint: 8A17 B57C 6879 1863 DE55 8012 AB4D 6098 8826 6868
pgpvdUA6j4oTx.pgp
Description: PGP signature
_______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
