Tutorials Point


  Python Basics
  Python Advanced
  Python Useful References
  Python Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Python os.fchown() Method


previous next AddThis Social Bookmark Button


Description:

This method changes the owner and group id of the file given by fd to the numeric uid and gid. To leave one of the ids unchanged, set it to -1.

Note: This method is available Python 2.6 onwards.

Syntax:

os.fchown(fd, uid, gid);

Parameters:

Here is the detail of parameters:

  • fd: This is the file descriptor for which owner id and group id need to be setup.

  • uid: Owner ID to be set for the file.

  • gid: Group ID to be set for the file.

Example:

#!/usr/bin/python

import os, sys, stat

# Now open a file "/tmp/foo.txt"
fd = os.open( "/tmp", os.O_RDONLY )

# Set the user Id to 100 for this file.

os.fchown( fd, 100, -1)

# Set the group Id to 50 for this file.

os.fchown( fd, -1, 50)

print "Changed ownership successfully!!"

# Close opened file.
os.close( fd )

This would produce following result:

Changed ownership successfully!!


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names