Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:6.1.2 File Object CreationUp:6.1 osNext:6.1.4 Files and Directories

 
6.1.3 File Descriptor Operations

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

close(fd)
Close file descriptorfd.Availability: Macintosh, Unix, Windows.

Note: this function is intended for low-level I/O and must be appliedto a file descriptor as returned byopen() orpipe(). To close a ``file object'' returned by thebuilt-in functionopen() or bypopen() orfdopen(), use itsclose() method.

dup(fd)
Return a duplicate of file descriptorfd.Availability: Macintosh, Unix, Windows.

dup2(fd, fd2)
Duplicate file descriptorfd tofd2, closing the latterfirst if necessary.Availability: Unix, Windows.

fdatasync(fd)
Force write of file with filedescriptorfd to disk.Does not force update of metadata.Availability: Unix.

fpathconf(fd, name)
Return system configuration information relevant to an open file.name specifies the configuration value to retrieve; it may be astring which is the name of a defined system value; these names arespecified in a number of standards (POSIX.1, Unix95, Unix98, andothers). Some platforms define additional names as well. The namesknown to the host operating system are given in thepathconf_names dictionary. For configuration variables notincluded in that mapping, passing an integer forname is alsoaccepted.Availability: Unix.

Ifname is a string and is not known,ValueError israised. If a specific value forname is not supported by thehost system, even if it is included inpathconf_names, anOSError is raised witherrno.EINVAL for theerror number.

fstat(fd)
Return status for file descriptorfd, likestat().Availability: Unix, Windows.

fstatvfs(fd)
Return information about the filesystem containing the file associatedwith file descriptorfd, likestatvfs().Availability: Unix.

fsync(fd)
Force write of file with filedescriptorfd to disk. On Unix,this calls the nativefsync() function; on Windows, theMS_commit() function.

If you're starting with a Python file objectf, first dof.flush(), and then doos.fsync(f.fileno()),to ensure that all internal buffers associated withf are writtento disk.Availability: Unix, and Windows starting in 2.2.3.

ftruncate(fd, length)
Truncate the file corresponding to file descriptorfd, so that it is at mostlength bytes in size.Availability: Unix.

isatty(fd)
Return1 if the file descriptorfd is open and connected to atty(-like) device, else0.Availability: Unix.

lseek(fd, pos, how)
Set the current position of file descriptorfd to positionpos, modified byhow:0 to set the positionrelative to the beginning of the file;1 to set it relative tothe current position;2 to set it relative to the end of thefile.Availability: Macintosh, Unix, Windows.

open(file, flags[, mode])
Open the filefile and set various flags according toflags and possibly its mode according tomode.The defaultmode is0777 (octal), and the current umaskvalue is first masked out. Return the file descriptor for the newlyopened file.Availability: Macintosh, Unix, Windows.

For a description of the flag and mode values, see the C run-timedocumentation; flag constants (likeO_RDONLY andO_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 functionopen(), which returns a ``fileobject'' withread() andwrite() methods (and manymore).

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 thepty 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 mostn bytes from file descriptorfd.Return a string containing the bytes read. If the end of the filereferred to byfd has been reached, an empty string isreturned.Availability: Macintosh, Unix, Windows.

Note: this function is intended for low-level I/O and must be appliedto a file descriptor as returned byopen() orpipe(). To read a ``file object'' returned by thebuilt-in functionopen() or bypopen() orfdopen(), orsys.stdin, use itsread() orreadline() methods.

tcgetpgrp(fd)
Return the process group associated with the terminal given byfd (an open file descriptor as returned byopen()).Availability: Unix.

tcsetpgrp(fd, pg)
Set the process group associated with the terminal given byfd (an open file descriptor as returned byopen())topg.Availability: Unix.

ttyname(fd)
Return a string which specifies the terminal device associated withfile-descriptorfd. Iffd is not associated with a terminaldevice, an exception is raised.Availability: Unix.

write(fd, str)
Write the stringstr to file descriptorfd.Return the number of bytes actually written.Availability: Macintosh, Unix, Windows.

Note: this function is intended for low-level I/O and must be appliedto a file descriptor as returned byopen() orpipe(). To write a ``file object'' returned by thebuilt-in functionopen() or bypopen() orfdopen(), orsys.stdout orsys.stderr, useitswrite() method.

The following data items are available for use in constructing theflags parameter to theopen() 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 theflag argument to theopen() function.These can be bit-wise OR'd together.Availability: Macintosh, Unix, Windows.

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


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:6.1.2 File Object CreationUp:6.1 osNext:6.1.4 Files and Directories
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp