我一直在尝试按照这篇文章Changing file permission in python更改我的python代码生成的目录和文件夹的权限。但是我仍然收到错误IOError: [Errno 13] Permission denied:
absPath = createFolder + "/" + collectionInterval
print absPath
if not os.path.exists(absPath):
os.system("sudo mkdir " + absPath)
os.chmod(absPath, stat.S_IRWXO | stat.S_IRWXU | stat.S_IRWXG)
scriptName = ipAddress.replace(".", "")
#create script file and save it in that location
#need to replace "name" with a distinguishable name
saveFile = absPath + "/" + scriptName + "_" + script["datasourceID"] + "_" + script["datapointID"] + ".py"
print saveFile
with open(saveFile, "w") as script_file:
os.chmod(saveFile, stat.S_IRWXO | stat.S_IRWXU | stat.S_IRWXG)
script_file.write(script)