GNU Info

Info Node: (python2.1-lib.info)File Descriptor Operations

(python2.1-lib.info)File Descriptor Operations


Next: Files and Directories Prev: File Object Creation Up: os
Enter node , (file) or (file)node

File Descriptor Operations
--------------------------

These functions operate on I/O streams referred to using file
descriptors.

`close(fd)'
     Close file descriptor FD.  Availability: Macintosh, UNIX, Windows.

     Note: this function is intended for low-level I/O and must be
     applied to a file descriptor as returned by `open()' or `pipe()'.
     To close a "file object" returned by the built-in function
     `open()' or by `popen()' or `fdopen()', use its `close()' method.

`dup(fd)'
     Return a duplicate of file descriptor FD.  Availability:
     Macintosh, UNIX, Windows.

`dup2(fd, fd2)'
     Duplicate file descriptor FD to FD2, closing the latter first if
     necessary.  Availability: UNIX, Windows.

`fpathconf(fd, name)'
     Return system configuration information relevant to an open file.
     NAME 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, Unix95, Unix98, and
     others).  Some platforms define additional names as well.  The
     names known to the host operating system are given in the
     `pathconf_names' dictionary.  For configuration variables not
     included in that mapping, passing an integer for NAME is also
     accepted.  Availability: UNIX.

     If NAME is a string and is not known, `ValueError' is raised.  If
     a specific value for NAME is not supported by the host system,
     even if it is included in `pathconf_names', an `OSError' is raised
     with `errno.EINVAL' for the error number.

`fstat(fd)'
     Return status for file descriptor FD, like `stat()'.
     Availability: UNIX, Windows.

`fstatvfs(fd)'
     Return information about the filesystem containing the file
     associated with file descriptor FD, like `statvfs()'.
     Availability: UNIX.

`ftruncate(fd, length)'
     Truncate the file corresponding to file descriptor FD, so that it
     is at most LENGTH bytes in size.  Availability: UNIX.

`isatty(fd)'
     Return `1' if the file descriptor FD is open and connected to a
     tty(-like) device, else `0'.  Availability: UNIX

`lseek(fd, pos, how)'
     Set the current position of file descriptor FD to position POS,
     modified by HOW: `0' to set the position relative to the beginning
     of the file; `1' to set it relative to the current position; `2'
     to set it relative to the end of the file.  Availability:
     Macintosh, UNIX, Windows.

`open(file, flags[, mode])'
     Open the file FILE and set various flags according to FLAGS and
     possibly its mode according to MODE.  The default MODE is `0777'
     (octal), and the current umask value is first masked out.  Return
     the file descriptor for the newly opened file.  Availability:
     Macintosh, UNIX, Windows.

     For a description of the flag and mode values, see the C run-time
     documentation; flag constants (like `O_RDONLY' and `O_WRONLY') are
     defined in this module too (see below).

     Note: this function is intended for low-level I/O.  For normal
     usage, use the built-in function `open()', which returns a "file
     object" with `read()' and `write()' methods (and many more).

`openpty()'
     Open a new pseudo-terminal pair. Return a pair of file descriptors
     `(MASTER, SLAVE)' for the pty and the tty, respectively. For a
     (slightly) more portable approach, use the `pty'  module.
     Availability: Some flavors of UNIX

`pipe()'
     Create a pipe.  Return a pair of file descriptors `(R, W)' usable
     for reading and writing, respectively.  Availability: UNIX,
     Windows.

`read(fd, n)'
     Read at most N bytes from file descriptor FD.  Return a string
     containing the bytes read.  Availability: Macintosh, UNIX, Windows.

     Note: this function is intended for low-level I/O and must be
     applied to a file descriptor as returned by `open()' or `pipe()'.
     To read a "file object" returned by the built-in function `open()'
     or by `popen()' or `fdopen()', or `sys.stdin', use its `read()' or
     `readline()' methods.

`tcgetpgrp(fd)'
     Return the process group associated with the terminal given by FD
     (an open file descriptor as returned by `open()').  Availability:
     UNIX.

`tcsetpgrp(fd, pg)'
     Set the process group associated with the terminal given by FD (an
     open file descriptor as returned by `open()') to PG.
     Availability: UNIX.

`ttyname(fd)'
     Return a string which specifies the terminal device associated with
     file-descriptor FD.  If FD is not associated with a terminal
     device, an exception is raised.  Availability: UNIX.

`write(fd, str)'
     Write the string STR to file descriptor FD.  Return the number of
     bytes actually written.  Availability: Macintosh, UNIX, Windows.

     Note: this function is intended for low-level I/O and must be
     applied to a file descriptor as returned by `open()' or `pipe()'.
     To write a "file object" returned by the built-in function
     `open()' or by `popen()' or `fdopen()', or `sys.stdout' or
     `sys.stderr', use its `write()' method.

The following data items are available for use in constructing the
FLAGS parameter to the `open()' function.

`O_RDONLY'

`O_WRONLY'

`O_RDWR'

`O_NDELAY'

`O_NONBLOCK'

`O_APPEND'

`O_DSYNC'

`O_RSYNC'

`O_SYNC'

`O_NOCTTY'

`O_CREAT'

`O_EXCL'

`O_TRUNC'
     Options for the FLAG argument to the `open()' function.  These can
     be bit-wise OR'd together.  Availability: Macintosh, UNIX, Windows.

`O_BINARY'
     Option for the FLAG argument to the `open()' function.  This can
     be bit-wise OR'd together with those listed above.  Availability:
     Macintosh, Windows.


automatically generated by info2www version 1.2.2.9