使用python更改文件权限

使用python更改文件权限

如何通过 python 脚本向任何文件提供权限?

我正在开发一个网站,所以我需要.txt在特定位置创建一个文件,就像var/www/html/我尝试的那样:

import subprocess
f = open('/path/to/folder/or/file.txt', 'w')
subprocess.call(['chmod', '0777', '/path/to/folder/or/file.txt'])

它抛出了chmod: changing permissions of '/path/to/folder/or/file.txt': Operation not permitted

我该如何克服这个问题?

相关内容