[英]How would one programmatically stop an app from reading computer files?
In a language like Python for scripting, how would you stop an app from having access to reading computer files, especially sensitive system-level ones?在像 Python 这样用于脚本的语言中,您将如何阻止应用程序读取计算机文件,尤其是敏感的系统级文件?
Edit: To be clear, I mean set permissions for that app to not have access to computer files, even after the script is done running (setting permissions).编辑:要清楚,我的意思是将该应用程序设置为无权访问计算机文件,即使在脚本运行完成后(设置权限)也是如此。
You should run your python script as a non-privileged user and read a file after validating the access您应该以非特权用户身份运行 python 脚本并在验证访问权限后读取文件
# check readability of the path
if os.access("file.txt", os.R_OK):
# open txt file as file
with open("file.tx") as file:
return file.read()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.