Fred Drake | 21572fd | 1999-06-14 19:47:47 +0000 | [diff] [blame^] | 1 | \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 | |
| 9 | The \module{linecache} module allows one to get any line from any file, |
| 10 | while attempting to optimize internally, using a cache, the common case |
| 11 | where many lines are read from a file. |
| 12 | |
| 13 | The \module{linecache} module defines the following functions: |
| 14 | |
| 15 | \begin{funcdesc}{getline}{filename, lineno} |
| 16 | Get line \var{lineno} from file named \var{filename}. This function |
| 17 | will never throw an exception --- it will return \code{''} on errors. |
| 18 | |
| 19 | If a file named \var{filename} is not found, the function will look |
| 20 | for it in the module search path. |
| 21 | \end{funcdesc} |
| 22 | |
| 23 | \begin{funcdesc}{clearcache}{} |
| 24 | Clear the cache. You might want to use this function if you know that |
| 25 | you do not need to read lines from many of files you already read from |
| 26 | using this module. |
| 27 | \end{funcdesc} |
| 28 | |
| 29 | \begin{funcdesc}{checkcache}{} |
| 30 | Check the cache is still valid. You might want to use this function if |
| 31 | you suspect that files you read from using this module might have |
| 32 | changed. |
| 33 | \end{funcdesc} |
| 34 | |
| 35 | Example: |
| 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} |