Specifying arguments with spaces for running a python script

where “argument 1” is a single argument.

You’ve basically answered your own question there, "argument 1" is indeed a single argument.

In other words, you need to quote it, something like one of:

python testProgram.py "argument 1" 'argument 2'

This isn’t actually a Python issue however, it depends on the shell that you’re using to run the Python script.

For example, with bash, there are differences between the single and double quotes, the most important of which is probably the various expansions like $HOME – the single quoted variant does not do those expansions.

Leave a Comment