Next / Previous / Contents / TCC Help System / NM Tech homepage

20.12. Low-level file functions in the os module

This group of functions operates on low-level file descriptors, which use integers for file handles. In these functions, the f argument is a low-level-file descriptor. These functions are part of module os.

Use these functions only when you really need low-level I/O. Most applications will use a “file object” as produced by the built-in open() function; see file objects above.

close(f)

Close file f.

dup(f)

Returns a new file descriptor that is a duplicate of f.

fstat(f)

Return the file's status tuple in the same format as os.stat().

lseek(f,p,w)

Change the current position of f. The p and f arguments are interpreted as in the .seek() method for file objects.

open(p,f,m)

Open the file at pathname p. The value f describes various options, such as read or write access, and whether to create the file if it doesn't exist; see /usr/include/fcntl.h for C-language definitions for the f value. If you are creating the file, you can supply m to specify the initial permissions of the file as in chmod(). Returns a low-level file descriptor.

pipe()

Create a pipe. Returns a tuple (fr,fw) of two file descriptors, fr for reading and fw for writing.

read(f,n)

Read no more than n bytes. Returns the data as a string.

write(f,s)

Write string s.