Passing a string in csh and then in python script break spaces

I have a little CSH script that calls a python script. I am trying to pass a string to a python script by calling a CSH script, but it breaks the whitespace by processing with argparse in python. I need this CSH script because after executing python there is some old code that I need to use.

CSH script:
Just a python script call passing all python string argumentssys.argv

#!/bin/csh
echo  $argv[1-]
python soocc.py $argv[1-]

python script:
This script must identify an argument of type: -opt "+arg1=1 +arg2=3 +arg3=0"before parsing argparse. So, first it identifies if there is -optin sys.argv, write a line in the variable, and then delete -opt "arg1=1 arg2=3 arg3=0"from sys.argv. This way argparse will not process -opt(because argparse looks at + arg1 as an argument, even if it is inside a double quote).

#!usr/bin/python
# -*- coding: UTF-8 -*-

# show sys.argv list
print sys.argv  
if '-opt' in sys.argv:
  xipdef.opt = sys.argv[sys.argv.index('-opt') + 1] #attributes the string after "-opt" to xipdef.opt
  sys.argv.remove(sys.argv[sys.argv.index('-opt') + 1])  # remove "<string>" from sys.argv
  sys.argv.remove(sys.argv[sys.argv.index('-opt')])  # remove "-opt" from sys.argv

print sys.argv

Problems:

soocc.csh -opt '"+arg1=1 +arg2=3 +arg3=0"'

Returns csh echo:

-opt "+arg1=1 +arg2=3 +arg3=0"

So far so good. The problem is when the arguments are passed to a python script. First result print sys.argv:

['soocc.csh','-opt', '"+arg1=1', '+arg2=3', '+arg3=0"']

The string inside the double quotes is split into a space on sys.argv. I was expecting something like:

['soocc.csh','-opt', "+arg1=1 +arg2=3 +arg3=0"]

Can anyone help me find what is wrong?

+4
source share
1

... .

opts = []
holder = []
for arg in sys.argv:
    if '+' in arg:
        holder.append(arg.replace('"', ''))
    else:
        opts.append(arg)
holder = " ".join(holder)
opts.append(holder)
sys.argv = opts
print sys.argv

0

All Articles