好吧,我花了一个小时编写了一个允许用户创建一个项目的代码,但是现在我很惊讶。我尝试使用shutil
和copyfile
复制文件。这是我的代码:
class Adder():
@staticmethod
def AddResource(resourcepath,resourcename,rootpath,projectname):
resfi = rootpath + projectname + "/" + projectname + ".sceneproj/Resources"
resfo = rootpath + projectname + "/" + projectname + ".sceneproj/project.scresources"
shutil.copyfile(resourcepath + resourcename, resfo) # copy resource into resource folder
with open(resfi, 'a') as resfile:
resfile.write("project.scresources/" + resourcename)
resfile.close()
开始时:
^{pr2}$但现在我遇到了以下问题:
Traceback (most recent call last): File "project.py", line 28, in adder.AddResource('/users/jan/downloads/', 'polygon_grey_background.jpg', '/ users/jan/documents/', 'MyCoolScene') File "project.py", line 21, in AddResource shutil.copyfile(resourcepath + resourcename, resfo) # copy resource into res ource folder File "C:\Python27\lib\shutil.py", line 83, in copyfile with open(dst, 'wb') as fdst: IOError: [Errno 13] Permission denied: '/users/jan/documents/MyCoolScene/MyCoolS cene.sceneproj/project.scresources'
意思是我没有复制文件的权限?但它是我的Documents
文件夹?我该怎么解决这个问题?在
~简
通过使用
copy
而不是copyfile
修复了此问题。在相关问题 更多 >
编程相关推荐