source: trunk/essentials/dev-lang/python/Doc/lib/liblinecache.tex

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

File size: 1.9 KB
Line 
1\section{\module{linecache} ---
2 Random access to text lines}
3
4\declaremodule{standard}{linecache}
5\sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
6\modulesynopsis{This module provides random access to individual lines
7 from text files.}
8
9
10The \module{linecache} module allows one to get any line from any file,
11while attempting to optimize internally, using a cache, the common case
12where many lines are read from a single file. This is used by the
13\refmodule{traceback} module to retrieve source lines for inclusion in
14the formatted traceback.
15
16The \module{linecache} module defines the following functions:
17
18\begin{funcdesc}{getline}{filename, lineno\optional{, module_globals}}
19Get line \var{lineno} from file named \var{filename}. This function
20will never throw an exception --- it will return \code{''} on errors
21(the terminating newline character will be included for lines that are
22found).
23
24If a file named \var{filename} is not found, the function will look
25for it in the module\indexiii{module}{search}{path} search path,
26\code{sys.path}, after first checking for a \pep{302} \code{__loader__}
27in \var{module_globals}, in case the module was imported from a zipfile
28or other non-filesystem import source.
29
30\versionadded[The \var{module_globals} parameter was added]{2.5}
31\end{funcdesc}
32
33\begin{funcdesc}{clearcache}{}
34Clear the cache. Use this function if you no longer need lines from
35files previously read using \function{getline()}.
36\end{funcdesc}
37
38\begin{funcdesc}{checkcache}{\optional{filename}}
39Check the cache for validity. Use this function if files in the cache
40may have changed on disk, and you require the updated version. If
41\var{filename} is omitted, it will check all the entries in the cache.
42\end{funcdesc}
43
44Example:
45
46\begin{verbatim}
47>>> import linecache
48>>> linecache.getline('/etc/passwd', 4)
49'sys:x:3:3:sys:/dev:/bin/sh\n'
50\end{verbatim}
Note: See TracBrowser for help on using the repository browser.