blob: 868ec6dca7d94049e4785aadb2fc0450f6b56c23 [file] [log] [blame]
Fred Drake21572fd1999-06-14 19:47:47 +00001\section{\module{linecache} ---
2 Treat files like lists of lines}
3
4\declaremodule{standard}{linecache}
5\sectionauthor{Moshe Zadka}{mzadka@geocities.com}
6\modulesynopsis{This module treats files like random-access lists of lines.}
7
8
9The \module{linecache} module allows one to get any line from any file,
10while attempting to optimize internally, using a cache, the common case
11where many lines are read from a file.
12
13The \module{linecache} module defines the following functions:
14
15\begin{funcdesc}{getline}{filename, lineno}
16Get line \var{lineno} from file named \var{filename}. This function
17will never throw an exception --- it will return \code{''} on errors.
18
19If a file named \var{filename} is not found, the function will look
20for it in the module search path.
21\end{funcdesc}
22
23\begin{funcdesc}{clearcache}{}
24Clear the cache. You might want to use this function if you know that
25you do not need to read lines from many of files you already read from
26using this module.
27\end{funcdesc}
28
29\begin{funcdesc}{checkcache}{}
30Check the cache is still valid. You might want to use this function if
31you suspect that files you read from using this module might have
32changed.
33\end{funcdesc}
34
35Example:
36
37\begin{verbatim}
38>>> import linecache
39>>> linecache.getline('/etc/passwd', 4)
40'sys:x:3:3:sys:/dev:/bin/sh\012'
41\end{verbatim}