bash like expansion

bill bill.pursell at gmail.com
Thu May 12 14:45:33 EDT 2005


Consider the following:

import os, commands
os.environ['QWE']="string with foo"
a = '$QWE  ${QWE/foo/baz}'
b = commands.getoutput('echo ' + a)


This does what I want, which is to expand
a according to the standard bash expansion rules
(so b now references "string with foo string with baz"),
but it doesn't feel right.

Is there a more pythonic way to interpret strings according
to shell rules for word expansion?  Relying on commands
feels like a kludge, and shlex is way too much work for this
(not to mention that it doesn't really address the issue).




More information about the Python-list mailing list