Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #44517

Mystery of module bindings!

Date 2013-04-29 12:30 -0700
From Peter Rowat <peter@pelican.ucsd.edu>
Subject Mystery of module bindings!
Newsgroups comp.lang.python
Message-ID <mailman.1161.1367263904.3114.python-list@python.org> (permalink)

Show all headers | View raw


This must be a trivial question:

I have "import numpy as np" in the python startup file.

A file called mod1.py contains "def myfn..."
 and inside myfn there is a call to, say, "np.convolve".

Interactively:
>python
.... (numpy imported as np)

>import mod1
>
>mod1.myfn(...)

Error: global name "np" is not known.
=======
Why is "np" not known to functions in an imported module ?
=======

I can fix this by including "import numpy as np" in any module that uses numpy
functions -- but then what is the point of having a startup file?

-- PeterR

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Mystery of module bindings! Peter Rowat <peter@pelican.ucsd.edu> - 2013-04-29 12:30 -0700
  Re: Mystery of module bindings! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-29 19:49 +0000

csiph-web