I have a string containing arguments e.g python program_name.py arg1 arg2
. I want to add an argument in a certain index, e.g 2, so, as in array indexing, it should result like this: python program_name.py my_argument arg1 arg2
.
In this case, there is no problem, I can just use:
s = "python program_name.py arg1 arg2"
l = s.split()
l.insert(2, "my_argument")
print "My final result:", ' '.join(l)
BUT, what happens if one of the arguments includes spaces? say a string argument like this Wow, this is a long argument
. When using it in the command like it obviously is wrapped with "
, how can I, then, accomplish my mission?
Example string: python program_name.py "My long string argument" another_one and_another_one
how do I end up with python program_name.py my_argument "My long string argument" another_one and_another_one
?