Skip to content Skip to sidebar Skip to footer

Sys.argv Arguments With Spaces

I'm trying to input folder names as sys.argv arguments, but am having problem with folder names that have spaces, which become multiple variables. For example, from the command li

Solution 1:

Space is the delimiter for command line arguments. You'll be better off not using spaces in your directory and file names if possible. For entering an argument which has space in it you'll have to enclose it in quotes "folder with space".

Program.py "D:\Users\Erick\Desktop\Folder Name"

Solution 2:

Solution 3:

To extend the simplicity of Arshiyan's answer for a case involving multiple paths, you could join the paths with a delimiter such as a hash, and then split the resulting string when it gets to python...

paths = " ".join(sys.argv[1:]).split("#")

Post a Comment for "Sys.argv Arguments With Spaces"