'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:

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 1:[1]

Either escape the inner quotes or use single quotes as the delimiter:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Barmar