Fred Drake | c7b5b3c | 1999-10-29 17:23:15 +0000 | [diff] [blame] | 1 | \section{\module{filecmp} --- |
| 2 | File Comparisons} |
| 3 | |
| 4 | \declaremodule{standard}{filecmp} |
| 5 | \sectionauthor{Moshe Zadka}{mzadka@geocities.com} |
| 6 | \modulesynopsis{Compare files efficiently.} |
| 7 | |
| 8 | The \module{filecmp} module defines a function to compare files, taking all |
| 9 | sort of short-cuts to make it a highly efficient operation. |
| 10 | |
| 11 | The \module{filecmp} module defines the following function: |
| 12 | |
| 13 | \begin{funcdesc}{cmp}{f1, f2\optional{, shallow\optional{, use_statcache}}} |
| 14 | Compare the files named \var{f1} and \var{f2}, returning \code{1} |
| 15 | if they seem equal, \code{0} otherwise. |
| 16 | |
| 17 | Unless \var{shallow} is given and is false, files with identical |
| 18 | \function{os.stat()} signatures are taken to be equal. If |
| 19 | \var{use_statcache} is given and is true, |
| 20 | \function{statcache.stat()} will be called rather then \var{os.stat()}. |
| 21 | |
| 22 | Files that were compared using this function will not be compared again |
| 23 | unless their \function{os.stat()} signature changes. Note that using |
| 24 | \var{use_statcache} true will cause the cache invalidation mechanism to |
| 25 | fail --- the stale stat value will be used from \refmodule{statcache}'s |
| 26 | cache. |
| 27 | |
| 28 | Note that no external programs are called from this module giving it |
| 29 | portability and efficiency. |
| 30 | \end{funcdesc} |
| 31 | |
| 32 | Example: |
| 33 | |
| 34 | \begin{verbatim} |
| 35 | >>> import filecmp |
| 36 | >>> filecmp.cmp('libundoc.tex', 'libundoc.tex') |
| 37 | 1 |
| 38 | >>> filecmp.cmp('libundoc.tex', 'lib.tex') |
| 39 | 0 |
| 40 | \end{verbatim} |