Commit 1dc98c44 authored by Skip Montanaro's avatar Skip Montanaro

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

module is __main__ and once when module is imported.
parent 62f9d7c0
......@@ -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}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment