Low-Level I/O operations
The os module contains a variety of low-level I/O functions
os.close(fd) # Close a file
os.dup(fd) # Duplicate file descriptor fd
os.dup2(oldfd,newfd) # Duplicate oldfd to newfd
os.fdopen(fd [,mode [,bufsize]]) # Create a file object from an fd
os.fstat(fd) # Return file status for fd
os.fstatvfs(fd) # Return file system info for fd
os.ftruncate(fd,size) # Truncate file to given size
os.lseek(fd,pos,how) # Seek to new position
# how = 0: beginning of file
# how = 1: current position
# how = 2: end of file
os.read(fd,n) # Read at most n bytes
os.write(fd,str) # Write data in str
Notes
- The os.fdopen() and f.fileno() methods convert between file objects and file descriptors.
|