python: Can't save figures in Directory with spaces

1k Views Asked by At

I've been creating figures using python matplotlib and saving them into my Dropbox folder for a while now using:

import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

plot = plt.figure(1)

Created figure....

plt.show()
pp=PdfPages("OutFileName.pdf")
pp.savefig(plot)
pp.close()

This worked for a really long time, and still works, as long as my Directory contains no spaces. However, the Dropbox settings have now changed and I have two Dropbox folders (Work and Personal). The directory is now: "~/Dropbox (Work)/MyFolder/'

Is there any way to work around this?

2

There are 2 best solutions below

0
On

You can use an underscore.

plt.show()
pp=PdfPages("~/Dropbox_Work/MyFolder/Out_File_Name.pdf")
pp.savefig(plot)
pp.close()
0
On

I tried to create an alias Dropbox folder with no spaces and replacing the directory read in by my program with the alias and it still didn't work. This lead me to believe that perhaps the problem wasn't the spaces but Dropbox. I restarted the computer and everything is back to running as it should.