Home  >  Article  >  Backend Development  >  What is the python os.chown() method? What does it do?

What is the python os.chown() method? What does it do?

乌拉乌拉~
乌拉乌拉~Original
2018-08-17 11:32:251720browse

Today in this article we will learn about the python os.chown() method. In the next article we will introduce the python os.chown() method, chown and chmod Looks very similar, but they are two completely different methods. I will introduce the chown() method in the next article.

Overview

The os.chown() method is used to change the file owner. If it is not modified, it can be set to -1. You need superuser permissions to perform permission modifications. operate.

Only supports use under Unix.

Grammar

##chown() method syntax format is as follows:

os.chown(path, uid, gid);

Parameters

path -- File path for setting permissions

uid -- User ID

gid -- User group ID

(This method has no return value.)

Example

The following example demonstrates the use of the lchmod() method:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os, sys

# 假定 /tmp/foo.txt 文件存在.
# 设置所有者 ID 为 100
os.chown("/tmp/foo.txt", 100, -1)

print "修改权限成功!!"

The output result of executing the above program is:

修改权限成功!!

The above is all the content of this article. I hope what I said and the examples I gave can be helpful to you.

For more related knowledge, please visit the

Python tutorial column on the php Chinese website.

The above is the detailed content of What is the python os.chown() method? What does it do?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn