【发布时间】:2015-01-31 11:20:47
【问题描述】:
好的,我在一个允许用户创建项目的代码上工作了一个小时,但现在我太棒了。我尝试使用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()
开始:
if __name__ == '__main__':
adder = Adder()
adder.AddResource('/users/jan/downloads/', 'polygon_grey_background.jpg', '/users/jan/documents/', 'MyCoolScene')
但是现在我遇到了以下问题:
Traceback(最近一次调用最后一次):文件“project.py”,第 28 行,在 adder.AddResource('/users/jan/downloads/', 'polygon_grey_background.jpg', '/users/jan/documents/', 'MyCoolScene') 文件“project.py”,第 21 行,在 AddResource 中 shutil.copyfile(resourcepath + resourcename, resfo) # 将资源复制到资源文件夹 File "C:\Python27\lib\shutil.py", 第 83 行,在副本文件中 使用 open(dst, 'wb') 作为 fdst: IOError: [Errno 13] Permission denied: '/users/jan/documents/MyCoolScene/MyCoolS cene.sceneproj/project.scresources'
意思是我没有复制文件的权限?但它是我的Documents 文件夹?我该如何解决这个问题?
~一月
【问题讨论】:
标签: python io copy errno shutil