【发布时间】:2021-01-21 03:28:00
【问题描述】:
我只是遇到了 chmod 方法的问题。我并不完全了解编程,但我有一些经验,我正在尝试编写一个脚本来跟踪我的小型家庭企业的收入和支出。
我认为问题在于写入文件的部分或 chmod 方法,两者都靠近底部:
weeklyDatetime = datetime.now()
weeklyDate = weeklyDatetime.strftime("%Y, %m, %V - Incomes")
incomeFileNameAndDirectory = incomesPath + "\\" + weeklyDate + ".txt"
weeklyIncomeFile= open(incomeFileNameAndDirectory, "w+")
weeklyIncomeFile.close()
makingChoice = True
while makingChoice == True:
print("1. Add another Income\n"
"2. Stop adding incomes")
addIncomeOrNo = input()
if addIncomeOrNo == "1":
print("Please enter the name of this income: ")
incomeName = input()
print("Please enter the amount of this income: ")
incomeAmount = input()
print("Please enter any additional descriptions for this income: ")
incomeDescription = input()
print("Thank you.\n")
with open(incomesPath, "a") as weeklyIncomeFile:
os.chmod(incomeFileNameAndDirectory, stat.S_IRWXO)
weeklyIncomeFile.write("\n" + incomeName + "\t\t" + incomeAmount + "\t\t" + incomeDescription)
我想我可能没有正确使用 os.chmod 方法?我仍然收到以下错误:
PermissionError: [Errno 13] Permission denied: 'C:\Users\iarko\Desktop\PCE Business\Financials\Incomes'
请告诉我问题是什么,感谢您的阅读!
【问题讨论】:
标签: python-3.x chmod