how to find the owner of a file or directory in python

前端 未结 7 1662
青春惊慌失措
青春惊慌失措 2020-12-03 04:38

I need a function or method in Python to find the owner of a file or directory.

The function should be like:

>>> find_owner(\"/home/somedir         


        
7条回答
  •  暖寄归人
    2020-12-03 05:13

    See os.stat. It gives you st_uid which is the user ID of the owner. Then you have to convert it to the name. To do that, use pwd.getpwuid.

提交回复
热议问题