Class around PixMap objects that allows more python-like access. By Joe Strout.
[python/dscho.git] / Doc / lib / libuser.tex
blobcd460ea344c26661d1bd7c9da4bf60b2a628ed7c
1 \section{\module{user} ---
2 User-specific configuration hook}
4 \declaremodule{standard}{user}
5 \modulesynopsis{A standard way to reference user-specific modules.}
8 \indexii{.pythonrc.py}{file}
9 \indexiii{user}{configuration}{file}
11 As a policy, Python doesn't run user-specified code on startup of
12 Python programs. (Only interactive sessions execute the script
13 specified in the \envvar{PYTHONSTARTUP} environment variable if it
14 exists).
16 However, some programs or sites may find it convenient to allow users
17 to have a standard customization file, which gets run when a program
18 requests it. This module implements such a mechanism. A program
19 that wishes to use the mechanism must execute the statement
21 \begin{verbatim}
22 import user
23 \end{verbatim}
25 The \module{user} module looks for a file \file{.pythonrc.py} in the user's
26 home directory and if it can be opened, exececutes it (using
27 \function{execfile()}\bifuncindex{execfile}) in its own (i.e. the
28 module \module{user}'s) global namespace. Errors during this phase
29 are not caught; that's up to the program that imports the
30 \module{user} module, if it wishes. The home directory is assumed to
31 be named by the \envvar{HOME} environment variable; if this is not set,
32 the current directory is used.
34 The user's \file{.pythonrc.py} could conceivably test for
35 \code{sys.version} if it wishes to do different things depending on
36 the Python version.
38 A warning to users: be very conservative in what you place in your
39 \file{.pythonrc.py} file. Since you don't know which programs will
40 use it, changing the behavior of standard modules or functions is
41 generally not a good idea.
43 A suggestion for programmers who wish to use this mechanism: a simple
44 way to let users specify options for your package is to have them
45 define variables in their \file{.pythonrc.py} file that you test in
46 your module. For example, a module \module{spam} that has a verbosity
47 level can look for a variable \code{user.spam_verbose}, as follows:
49 \begin{verbatim}
50 import user
51 try:
52 verbose = user.spam_verbose # user's verbosity preference
53 except AttributeError:
54 verbose = 0 # default verbosity
55 \end{verbatim}
57 Programs with extensive customization needs are better off reading a
58 program-specific customization file.
60 Programs with security or privacy concerns should \emph{not} import
61 this module; a user can easily break into a program by placing
62 arbitrary code in the \file{.pythonrc.py} file.
64 Modules for general use should \emph{not} import this module; it may
65 interfere with the operation of the importing program.
67 \begin{seealso}
68 \seemodule{site}{site-wide customization mechanism}
69 \refstmodindex{site}
70 \end{seealso}