Reputation: 569
I have this code:
def display(self):
print self.doc.toprettyxml(indent=" ")
strigName ='/Users/my_user/Desktop/python/' + str(datetime.datetime.now()) + '.xml'
print strigName
with open(strigName, "ws") as f:
f.write(self.doc.toprettyxml(indent=" "))
that saves and xml file with a timestamp on the name to a path. The problem is that I can only save it to the same directory the script is. When I try to save it in the path shown above it gives me "IOError: [Errno 13] Permission denied:" even running the python script with sudo, and yes my user is Admin. What's wrong?
Upvotes: 1
Views: 405
Reputation: 6177
Colons aren't allowed in OS X filenames. str(datetime.datetime.now())
is '2012-03-30 14:20:46'
You could replace the colons with dashes in your string before using it, or use something like time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
instead of datetime.datetime.now()
.
Upvotes: 1