Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python arguments passed with quotes

I'm trying to pass file list to my python script via argument:

python script.py -o aaa -s bbb "filename.txt" "filename2.txt" "file name3.txt"

Unfortunately ArgumentParser is ignoring quotes and instead of giving list of 3 files it gives me list of 4 elements as followed:

1) "filename.txt"
2) "filename2.txt"
3) "file
4) name3.txt"

It completely ignores quotes. How to make it work with quotes?

like image 627
J33nn Avatar asked Nov 25 '25 05:11

J33nn


1 Answers

Hard without seeing what you're using or any code. Your shell may be interfering, you may need to escape the spaces with \.

Example: python script.py -o a -f "file1.txt" "file\ 2.csv"

like image 119
Leigh Avatar answered Nov 27 '25 17:11

Leigh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!