spaces in python script arguments

Consider the following script:


import sys

first_arg = sys.argv[-2]
second_arg = sys.argv[-1]

print("first_arg="+first_arg)
print("second_arg="+second_arg)

Which I’m calling thusly:

blender -b utils/render.blend -P foo.py -- 'arg with space' 'otherarg'

Yields this result:

first_arg=space
second_arg=otherarg

Looks like spaces are not allowed in my python script arguments. Is this a limitation of blender? Is there a way around it?

Thanks.

This might be a shell-specific problem. I just tried it on the default OSX command line and it correctly kept the spaces. What OS/shell are you using?

you could " ".join() the sys.argv list and parse it yourself, respecting quotes if everything else fails