confusing behaviour of os.system

Ben Finney bignose+hates-spam at benfinney.id.au
Fri Apr 7 01:10:10 EDT 2006


"Todd" <goldfita at signalsguru.net> writes:

> Ben Cartwright wrote:
> > >>> print '/usr/bin/gnuclient -batch -l htmlize -eval "(htmlize-file> \"test.c\")"'
> > /usr/bin/gnuclient -batch -l htmlize -eval "(htmlize-file> "test.c")"
> > >>> print '/usr/bin/gnuclient -batch -l htmlize -eval "(htmlize-file> \\"test.c\\")"'
> > /usr/bin/gnuclient -batch -l htmlize -eval "(htmlize-file> \"test.c\")"
> > 
> > --Ben
> 
> Thanks!  Yay multiple layers of string interpretation.

If it helps, Python has "raw string" syntax that can help alleviate this.

    >>> print r'/usr/bin/gnuclient -batch -l htmlize -eval "(htmlize-file> \"test.c\")"'
    /usr/bin/gnuclient -batch -l htmlize -eval "(htmlize-file> \"test.c\")"

    >>> filename = "test.c"
    >>> cmd_template = r'/usr/bin/gnuclient -batch -l htmlize -eval "(htmlize-file> \"%s\")"'
    >>> command = cmd_template % filename
    >>> print command
    /usr/bin/gnuclient -batch -l htmlize -eval "(htmlize-file> \"test.c\")"


-- 
 \                          "Everything is futile."  -- Marvin of Borg |
  `\                                                                   |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list