Parsing Command line arguments in python which has spaces

Viewed 16644

I am invoking the script from ant . I am getting it as a single string from the caller but python is strangely treating it as two individual strings.I have script that reads a file name with it's path in windows. The folder structure may or may not have spaces in between

Here is an example

test.py D:/test/File Name

I know this can be done using optparse. Is there any way that i can read the param as single argument like i want to get it in sys.argv[index] (as a single string). I have tired prefixing with ' and " but with no success.

4 Answers

EDIT!! :
Depending on the encoder of your command line,
The ascii encoding reference for a space is normally %20
So instead of using a space use %20
https://www.w3schools.com/tags/ref_urlencode.ASP

As below

test.py "D:\test\File%20Name"

Be sure to write it as it is

Please vote in support if this helps you out. It wasn't as correct the first time I wrote it but now I believe that should do.

Related