add warning about situation where code may be executed twice, once when

module is __main__ and once when module is imported.
This commit is contained in:
Skip Montanaro 2001-06-08 14:40:28 +00:00
parent 62f9d7c021
commit 1dc98c44fe
1 changed files with 10 additions and 0 deletions

View File

@ -408,6 +408,16 @@ Simple fractions are also easier for people to understand, and that makes
for better documentation.
\end{enumerate}
\item Be careful if you have code that must only execute once.
If you have module-level code that must only execute once, a more foolproof
definition of \function{_test} is
\begin{verbatim}
def _test():
import doctest, sys
doctest.testmod(sys.modules["__main__"])
\end{verbatim}
\subsection{Soapbox}