Python3 Os Chown
# Python3.x Python3 os.chown() Method
[ Python3 OS File/Directory Methods](#)
* * *
### Overview
The os.chown() method is used to change the owner of a file. If you do not want to modify it, you can set it to -1. You need superuser privileges to perform permission modification operations.
It is only supported for use on Unix.
### Syntax
The syntax for the **chown()** method is as follows:
os.chown(path, uid, gid);
### Parameters
* **path** -- The file path for which to set permissions.
* **uid** -- The user ID of the owner.
* **gid** -- The group ID of the owner.
### Return Value
This method does not return a value.
### Example
The following example demonstrates the use of the chown() method:
#!/usr/bin/python3import os, sys # Assume the /tmp/foo.txt file exists. # Set the owner ID to 100 os.chown("/tmp/foo.txt", 100, -1)print ("Permissions modified successfully!!")
The output of the above program is:
Permissions modified successfully!!
[ Python3 OS File/Directory Methods](#)
YouTip