Python export script use "Space" in file name

I have a python script that exports a block and uses a name specified earlier in the script, as shown below

rs.Command("!_-Export “+filename+” _Enter")

This works fine, but if the name has a space in it, Rhino cuts the name of the file off at the “Space” and the name is shortened.

For example:

path = “C:\Users\kyle\Desktop”)
name = “Test Export”
filename = path + name
rs.Command("!_-Export “+filename+” _Enter")

I would expect the exported file to be “C:\Users\kyle\Desktop\Test Export.3dm”
Instead, I get “C:\Users\kyle\Desktop\Test.3dm”

What am i doing wrong?

You might try:

rs.Command('! _-Export ' + "filename" + ' _Enter')

I actually prefer something like this:

rs.Command('! _-Export "{}" _Enter'.format(filename))


Thank you!

I used the second suggestion and it worked great.