Can';无法获得使用python将.xml文件保存到磁盘的权限
我有以下代码:Can';无法获得使用python将.xml文件保存到磁盘的权限,python,macos,file,permissions,save,Python,Macos,File,Permissions,Save,我有以下代码: 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.toprettyx
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=" "))
将名称上带有时间戳的xml文件保存到路径。问题是我只能将它保存到脚本所在的目录中。当我尝试将其保存在上面显示的路径中时,它会给我“IOError:[Errno 13]权限被拒绝:”即使使用sudo运行python脚本,是的,我的用户是Admin。怎么了?OS X文件名中不允许使用冒号
str(datetime.datetime.now())
is'2012-03-30 14:20:46'
您可以在使用字符串之前将冒号替换为破折号,或者使用类似于
time.strftime(“%Y-%m-%d-%H-%m-%S”,time.localtime())
的内容,而不是datetime.datetime.now()
OS X文件名中不允许使用冒号str(datetime.datetime.now())
is'2012-03-30 14:20:46'
您可以在使用字符串之前将冒号替换为破折号,或者使用类似于
time.strftime(“%Y-%m-%d-%H-%m-%S”,time.localtime())
的内容,而不是datetime.datetime.now()
您完全控制该目录吗?这可能是访问权限/权限的情况,或者您正在写入的同一文件已经打开或正被其他服务使用!检查你的路线?你在使用哪个操作系统,如果你在使用sudo,我假设它是linux?通常没有/Users文件夹,哪种模式是“ws”我以前没有见过?你完全控制那个目录吗?这可能是访问权限/权限的情况,或者您正在写入的同一文件已经打开或正被其他服务使用!检查你的路线?你在使用哪个操作系统,如果你在使用sudo,我假设它是linux?通常没有/Users文件夹,而且哪种模式是“ws”我以前没有见过?POSIX层的Mac OS X文件名中允许使用冒号touch~/colon:colon
:-)在Finder中,它显示为/
,当然,这也很奇怪,因为Finder似乎不再喜欢以冒号分隔的文件名了。:-)POSIX层的Mac OS X文件名中允许使用冒号touch~/colon:colon
:-)在Finder中,它显示为/
,当然,这也很奇怪,因为Finder似乎不再喜欢以冒号分隔的文件名了。:-)