- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change file permissions in Python?
To change the permission of a file, you can use the os.chmod(file, mode) call. Note that the mode should be specified in octal representation and therefore must begin with a 0o. For example, to make a file readonly, you can set the permission to 0o777, you can use:
>>> import os >>> os.chmod('my_file', 0o777)
You can also use flags from the stat module. You can read more about these flags here: http://docs.python.org/2/library/stat.html
Another way to acheive it is using a subprocess call:
>>> import subprocess >>> subprocess.call(['chmod', '0444', 'my_file'])
- File Permissions in C#
- File Permissions in java
- How to set file permissions in Java?
- How to check the permissions of a file using Python?
- How to Copy File Permissions and Ownership to Another File in Linux?
- How to change file extension in Python?
- How to change the user and group permissions for a directory using Python?
- How to change the permission of a file using Python?
- How to change the mode of a file using Python?
- How to change the owner of a file using Python?
- How to check the permissions of a directory using Python?
- How to Copy NTFS permissions using PowerShell?
- Getting root permissions on a file inside of vi on Linux
- How to change file or directory permission in Linux/Unix?
- How to change the file owner and group in Linux?