当我运行从bat文件寻址的python脚本时,它工作正常。 尝试使用Windows Task Scheduler运行它,我得到:
with open('source.txt', '+w') as sour: PermissionError: [Errno 13] Permission denied: 'source.txt'
有什么想法吗?
答案 0 :(得分:2)
从Task Scheduler运行时,很可能您当前的工作目录不可写。您可以通过简单地检查
print(os.getcwd())
修复非常简单-只需使用其他位置即可,即使用文件的绝对路径或使用os.fchdir()
来更改目录。