Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/liblinecache.tex @ 22360:c8a6ea00a9e1 legacy-trunk
restructure a bit to not rely on test case execution ordering
add test case for bug #482460
| author | Skip Montanaro <skip@pobox.com> |
|---|---|
| date | Sun, 17 Mar 2002 23:03:42 +0000 |
| parents | c7c404b35f33 |
| children | 4dd97c37c2cc |
| rev | line source |
|---|---|
|
10982
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1 \section{\module{linecache} --- |
| 11003 | 2 Random access to text lines} |
|
10982
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
3 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
4 \declaremodule{standard}{linecache} |
|
15467
d7864345b1c8
Update Moshe Zadka's email address to one works and might last a while.
Fred Drake <fdrake@acm.org>
parents:
12223
diff
changeset
|
5 \sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il} |
| 11003 | 6 \modulesynopsis{This module provides random access to individual lines |
| 7 from text files.} | |
|
10982
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
8 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
9 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
10 The \module{linecache} module allows one to get any line from any file, |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
11 while attempting to optimize internally, using a cache, the common case |
| 11003 | 12 where many lines are read from a single file. This is used by the |
| 13 \refmodule{traceback} module to retrieve source lines for inclusion in | |
| 14 the formatted traceback. | |
|
10982
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
16 The \module{linecache} module defines the following functions: |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
17 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
18 \begin{funcdesc}{getline}{filename, lineno} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
19 Get line \var{lineno} from file named \var{filename}. This function |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11003
diff
changeset
|
20 will never throw an exception --- it will return \code{''} on errors |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11003
diff
changeset
|
21 (the terminating newline character will be included for lines that are |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11003
diff
changeset
|
22 found). |
|
10982
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
23 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
24 If a file named \var{filename} is not found, the function will look |
| 11003 | 25 for it in the module\indexiii{module}{search}{path} search path, |
| 26 \code{sys.path}. | |
|
10982
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
27 \end{funcdesc} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
28 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
29 \begin{funcdesc}{clearcache}{} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11003
diff
changeset
|
30 Clear the cache. Use this function if you no longer need lines from |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11003
diff
changeset
|
31 files previously read using \function{getline()}. |
|
10982
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
32 \end{funcdesc} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
33 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
34 \begin{funcdesc}{checkcache}{} |
| 11003 | 35 Check the cache for validity. Use this function if files in the cache |
| 36 may have changed on disk, and you require the updated version. | |
|
10982
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
37 \end{funcdesc} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
38 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
39 Example: |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
40 |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
41 \begin{verbatim} |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
42 >>> import linecache |
|
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
43 >>> linecache.getline('/etc/passwd', 4) |
|
16226
c7c404b35f33
Show '\011', '\012', and '\015' as '\t', '\n', '\r' in strings.
Ka-Ping Yee <ping@zesty.ca>
parents:
15467
diff
changeset
|
44 'sys:x:3:3:sys:/dev:/bin/sh\n' |
|
10982
bef46ea5ef75
New sections from Moshe Zadka <moshez@math.huji.ac.il>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
45 \end{verbatim} |
