File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,19 +37,17 @@ \section{Built-in Functions \label{built-in-funcs}}
3737 a non-empty \var {fromlist} argument is given, the module named by
3838 \var {name} is returned. This is done for compatibility with the
3939 bytecode generated for the different kinds of import statement; when
40- using \samp {import spam.ham.eggs}, the top-level package \code {spam}
40+ using \samp {import spam.ham.eggs}, the top-level package \module {spam}
4141 must be placed in the importing namespace, but when using \samp {from
4242 spam.ham import eggs}, the \code {spam.ham} subpackage must be used
4343 to find the \code {eggs} variable. As a workaround for this
4444 behavior, use \function {getattr()} to extract the desired
4545 components. For example, you could define the following helper:
4646
4747\begin {verbatim }
48- import string
49-
5048def my_import(name):
5149 mod = __import__(name)
52- components = string .split(name, '.')
50+ components = name .split('.')
5351 for comp in components[1:]:
5452 mod = getattr(mod, comp)
5553 return mod
You can’t perform that action at this time.
0 commit comments