Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea49de3

Browse files
committed
minor cleanup of example
1 parent ff381e1 commit ea49de3

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

Doc/lib/libuser.tex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ \section{\module{user} ---
4848

4949
\begin{verbatim}
5050
import user
51-
try:
52-
verbose = user.spam_verbose # user's verbosity preference
53-
except AttributeError:
54-
verbose = 0 # default verbosity
51+
52+
verbose = bool(getattr(user, "spam_verbose", 0))
5553
\end{verbatim}
5654

55+
(The three-argument form of \function{getattr()} is used in case
56+
the user has not defined \code{spam_verbose} in their
57+
\file{.pythonrc.py} file.)
58+
5759
Programs with extensive customization needs are better off reading a
5860
program-specific customization file.
5961

0 commit comments

Comments
 (0)