Use three different quotation marks in a bash command in Python scripts
Question: I want to have three different quotation marks in a python script, because I
want to execute a two-line python command, on a different computer. For
example:

    
    
    import commands
    command = "ssh someothercomputer 'python -c `import psutil; print psutil.cpu_percent()`'"
    output = commands.getstatusoutput(command)[1]
    

However, the backticks are not recognized as quotation marks. The error is the
following:

    
    
    "Badly placed ()'s.\nArgument expected for the -c option\nusage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...\nTry `python -h' for more information."
    

How can I get this to work?


Answer: Instead of using backticks, you can escape the inner quotation marks, to have
them in `command`. Like this:

    
    
    command =  "ssh someothercomputer 'python -c \"import psutil; print psutil.cpu_percent()\"'"
    

Executing this command with `commands` yields the wanted output (the current
cpu percentage at the other computer)

