Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass string argument to the python script saving quotes in it

I am having trouble with passing a string argument to a Python script.

I need to pass a string in this format: "{"test_key_1": [1, 3], "test_key_2": [5]}"

but when I am doing this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

test_script.py --test_arg "{"test_key_1": [1, 3], "test_key_2": [5]}"

I am getting this string inside the script:

'{test_key_1: [1, 3], test_ket_2: [5]}'

Why did my double quotes disappear?

I need to do json.loads(string_argument) after I get the argument, but it fails because of the wrong format.

>Solution :

You need to escape the double quotes like this:

test_script.py --test_arg "{\"test_key_1\": [1, 3], \"test_key_2\": [5]}"

or like just change the delimiters like this:

test_script.py --test_arg '{"test_key_1": [1, 3], "test_key_2": [5]}'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading