Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีเปลี่ยน Permission ของไฟล์ใน Python

ใช้ os.chmod(file, mode) เปลี่ยน permission mode เป็น octal (ขึ้นต้น 0o) เช่น 0o777

>>> import os
>>> os.chmod('my_file', 0o777)

หรือใช้ flags จากโมดูล stat หรือ subprocess.call(['chmod', '0444', 'my_file'])