In other words, is there a way to distinguish the input Hello World
and the input Hello World
using sys.argv
or other built-in methods like argparse
?
Asked
Active
Viewed 129 times
0

gurkensaas
- 793
- 1
- 5
- 29
-
1The arguments are separated and passed into your program by your shell. Python only gets them as separate words: it is outside Python's control. – khelwood Jan 23 '22 at 13:11
-
1Assuming you're on a Unix-like system, your code won't even _see_ those spaces. The Shell processes those arguments then essentially passes them into your code as `["Hello", "World"]`. If care about whitespace you'll have to pass them as a single argument, e.g. `python foo.py "Hello World"` or `python foo.py Hello\ World`. – ChrisGPT was on strike Jan 23 '22 at 13:12
-
`"Hello World"` – Tomerikoo Jan 23 '22 at 13:12
-
Related (possibly a duplicate): [Specifying arguments with spaces for running a python script](https://stackoverflow.com/q/11894815/6045800) – Tomerikoo Jan 23 '22 at 13:13
1 Answers
-1
Word splitting is performed by the shell, long before the arguments are passed to the utility. The utility never gets to see the command line, only the arguments array.

Jörg W Mittag
- 363,080
- 75
- 446
- 653