Python Tutorial ( PDFDrive )
Read String is : This is testPython is a great language.Yeah its great!!Current I/O pointer position :45Closed the file successfully!!os.fpathconf(fd, name) Description The method fpathconf() returns system configuration information relevant to an open file.This variable is verysimilar to unix system call fpathconf() and accept the similar arguments.Syntax Following is the syntax for fpathconf() method:os.fpathconf(fd, name)Parameters • fd -- This is the file descriptor for which system configuration information is to be returned.• name -- This specifies the configuration value to retrieve; it may be a string, which is the name of a definedsystem value; these names are specified in a number of standards (POSIX.1, Unix 95, Unix 98, and others).The names known to the host operating system are given in theos.pathconf_names dictionary.Return Value This method returns system configuration information relevant to an open file.ExampleThe following example shows the usage of fpathconf() method.#!/usr/bin/pythonimport os, sys# Open a filefd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )print "%s" % os.pathconf_names# Now get maximum number of links to the file.no = os.fpathconf(fd, 'PC_LINK_MAX')print "Maximum number of links to the file. :%d" % no# Now get maximum length of a filenameno = os.fpathconf(fd, 'PC_NAME_MAX')print "Maximum length of a filename :%d" % no# Close opened fileos.close( fd)print "Closed the file successfully!!"Let us compile and run the above program, this will produce the following result:TUTORIALS POINT Simply Easy Learning
{'PC_MAX_INPUT': 2, 'PC_VDISABLE': 8, 'PC_SYNC_IO': 9,'PC_SOCK_MAXBUF': 12, 'PC_NAME_MAX': 3, 'PC_MAX_CANON': 1,'PC_PRIO_IO': 11, 'PC_CHOWN_RESTRICTED': 6, 'PC_ASYNC_IO': 10,'PC_NO_TRUNC': 7, 'PC_FILESIZEBITS': 13, 'PC_LINK_MAX': 0,'PC_PIPE_BUF': 5, 'PC_PATH_MAX': 4}Maximum number of links to the file. :127Maximum length of a filename :255Closed the file successfully!!os.fstat(fd) Description The method fstat() returns information about a file associated with the fd. Here is the structure returned by fstatmethod:• st_dev: ID of device containing file• st_ino: inode number• st_mode: protection• st_nlink: number of hard links• st_uid: user ID of owner• st_gid: group ID of owner• st_rdev: device ID (if special file)• st_size: total size, in bytes• st_blksize: blocksize for filesystem I/O• st_blocks: number of blocks allocated• st_atime: time of last access• st_mtime: time of last modification• st_ctime: time of last status changeSyntax Following is the syntax for fstat() method:os.fstat(fd)Parameters • fd -- This is the file descriptor for which system information is to be returned.Return Value This method returns information about a file associated with the fd.ExampleThe following example shows the usage of chdir() method.#!/usr/bin/pythonimport os, sys# Open a filefd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )# Now get the toupleTUTORIALS POINT Simply Easy Learning
- Page 207 and 208: CHAPTER14Python FunctionAfunction i
- Page 209 and 210: #!/usr/bin/python# Function definit
- Page 211 and 212: return;# Now you can call printinfo
- Page 213 and 214: Inside the function : 30Outside the
- Page 215 and 216: A module is loaded only once, regar
- Page 217 and 218: 'sqrt', 'tan', 'tanh']Here, the spe
- Page 219 and 220: CHAPTER16Python Files I/OThis chapt
- Page 221 and 222: rb+WWbw+wb+AAba+ab+Opens a file for
- Page 223 and 224: fo.write( "Python is a great langua
- Page 225 and 226: EXAMPLE: Following is the example t
- Page 227 and 228: operations from the operating syste
- Page 229 and 230: # Close opened filefo.close()Let us
- Page 231 and 232: Parameters • NAReturn Value This
- Page 233 and 234: Example The following example shows
- Page 235 and 236: Parameters • offset -- This is th
- Page 237 and 238: Parameters • size -- If this opti
- Page 239 and 240: Description The method writelines()
- Page 241 and 242: 14151617181920212223242526272829303
- Page 243 and 244: 53545556575859606162os.symlink(src,
- Page 245 and 246: Return Value This method does not
- Page 247 and 248: • stat.S_IRGRP: Read by group.•
- Page 249 and 250: os.chroot("/tmp/usr")print "Changed
- Page 251 and 252: Parameters • fd -- This is the or
- Page 253 and 254: import os, sys# First go to the "/v
- Page 255 and 256: Description The method fchown() cha
- Page 257: Description The method fdopen() ret
- Page 261 and 262: Example The following example shows
- Page 263 and 264: # Open a filefd = os.open( "foo.txt
- Page 265 and 266: print "Current working dir : %s" %
- Page 267 and 268: path = "/var/www/html/foo.txt"fd =
- Page 269 and 270: Example The following example shows
- Page 271 and 272: _vti_txtrobots.txtitemlistingresume
- Page 273 and 274: # Close opened fileos.close( fd )#
- Page 275 and 276: dev_num = os.makedev(major_dnum, mi
- Page 277 and 278: Return Value This method does not
- Page 279 and 280: -rw-------. 1 root root 0 Apr 30 02
- Page 281 and 282: os.pathconf(path, name) Descriptio
- Page 283 and 284: Description The method popen() open
- Page 285 and 286: # !/usr/bin/pythonimport ossrc = '/
- Page 287 and 288: Syntax Following is the syntax for
- Page 289 and 290: Return Value This method does not
- Page 291 and 292: # stat informationstatinfo = os.sta
- Page 293 and 294: Description The method tcgetpgrp()
- Page 295 and 296: os.tempnam(dir, prefix)Parameters
- Page 297 and 298: Description The method ttyname() re
- Page 299 and 300: Return Value This method does not
- Page 301 and 302: Return Value This method returns t
- Page 303 and 304: KeyErrorNameErrorUnboundLocalErrorE
- Page 305 and 306: ......................else:If there
- Page 307 and 308: print "Error: can\'t find file or r
Read String is : This is testPython is a great language.
Yeah its great!!
Current I/O pointer position :45
Closed the file successfully!!
os.fpathconf(fd, name)
Description
The method fpathconf() returns system configuration information relevant to an open file.This variable is very
similar to unix system call fpathconf() and accept the similar arguments.
Syntax
Following is the syntax for fpathconf() method:
os.fpathconf(fd, name)
Parameters
• fd -- This is the file descriptor for which system configuration information is to be returned.
• name -- This specifies the configuration value to retrieve; it may be a string, which is the name of a defined
system value; these names are specified in a number of standards (POSIX.1, Unix 95, Unix 98, and others).
The names known to the host operating system are given in theos.pathconf_names dictionary.
Return Value
This method returns system configuration information relevant to an open file.
Example
The following example shows the usage of fpathconf() method.
#!/usr/bin/python
import os, sys
# Open a file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
print "%s" % os.pathconf_names
# Now get maximum number of links to the file.
no = os.fpathconf(fd, 'PC_LINK_MAX')
print "Maximum number of links to the file. :%d" % no
# Now get maximum length of a filename
no = os.fpathconf(fd, 'PC_NAME_MAX')
print "Maximum length of a filename :%d" % no
# Close opened file
os.close( fd)
print "Closed the file successfully!!"
Let us compile and run the above program, this will produce the following result:
TUTORIALS POINT
Simply Easy Learning