0

I'm using Python and Pandas to write multiple bash scripts. I have a pandas.Series containing the script. Simplified::

script = pd.Series([
'#!/bin/bash',
'#SBATCH --output "/home/path/output_filename.out"'
])

I then use script.to_csv('script_file.bat',index=False) to create the file. The output file looks like this:

#!/bin/bash
"#SBATCH --output ""/home/path/output_filename.out"""

I have tried all the suggestions here Python - Using quotation marks inside quotation marks (triple quotes, single and double quotes (as shown in the example) , escaping the quotemarks), as well as making the quoted text a variable, but none works.

doctorer
  • 1,672
  • 5
  • 27
  • 50

1 Answers1

1

It's possible to explicitly specify quoting for df.to_csv:

import csv

pd.DataFrame(script).to_csv("test.sh", index=False, header=False,
                            quoting=csv.QUOTE_NONE)

> #!/bin/bash
> #SBATCH --output "/home/path/output_filename.out"
koPytok
  • 3,453
  • 1
  • 14
  • 29