PermissionError-任务计划程序

时间:2020-04-12 19:29:38

标签: python windows batch-file scheduled-tasks

当我运行从bat文件寻址的python脚本时,它工作正常。 尝试使用Windows Task Scheduler运行它,我得到:

     with open('source.txt', '+w') as sour:
PermissionError: [Errno 13] Permission denied: 'source.txt'

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

从Task Scheduler运行时,很可能您当前的工作目录不可写。您可以通过简单地检查

print(os.getcwd())

修复非常简单-只需使用其他位置即可,即使用文件的绝对路径或使用os.fchdir()来更改目录。