[New-bugs-announce] [issue15028] PySys_SetArgv escapes quotes in argv[]

R.M.Bianchi report at bugs.python.org
Thu Jun 7 19:13:54 CEST 2012

New submission from R.M.Bianchi <riccardomaria.bianchi at gmail.com>:

Embedding Python in C++ I saw that if I pass this string below to the PySys_SetArgv, as one of the command-line arguments passed to an embedded script:


PySys_Argv transforms it escaping the single quotes, and in the Python side I get this value for sys.argv[i]:


It does not seem a problem of converting strings or char in the C++ sides, I checked them.

The problem appears just after the PySys_Argv call.

=== cut ===
Qt-Debug: python script command-line args: ("/afs/cern.ch/work/r/rbianchi/private/tdaq_4_0_0/dbe/cmt/pm_farm.py", "--safe-hw-tags", "--add='pcatd143'", "--net-label-name='("DC1","eth1")'", "newdb.data.xml")
pyout: sys.argv:
pyout: ['/afs/cern.ch/work/r/rbianchi/private/tdaq_4_0_0/dbe/cmt/pm_farm.py', '--safe-hw-tags', "--add='pcatd143'", '--net-label-name=\'("DC1","eth1")\'', 'newdb.data.xml']
=== cut ===

Please notice that the same script works perfectly with the same argument list in stand-alone mode (i.e. not embedded in C++).

Please also notice that in the embedded side the problem does not appear if I substitute the string passed as command line parameter from the original one:


to this one below, where I omit a level of quotes and I skip the double quotes:


In this last case the embedded script also works fine in the embedded world.

It seems to me an issue in PySys_SetArgv, while parsing the strings. But maybe I'm missing something.

Best regards,


components: Interpreter Core
messages: 162478
nosy: RMBianchi
priority: normal
severity: normal
status: open
title: PySys_SetArgv escapes quotes in argv[]
type: behavior
versions: Python 2.6

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list