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


Groups > comp.lang.python > #44523

Re: Mystery of module bindings!

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'say,': 0.05; 'startup': 0.05; 'error:': 0.07; 'interpreter.': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'imported': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:184.172': 0.09; 'received:gator410.hostgator.com': 0.09; 'subject:module': 0.09; '~ethan~': 0.09; 'python': 0.11; 'numpy': 0.16; 'received:69.93': 0.16; 'stuff.': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'module': 0.19; 'typing': 0.19; 'import': 0.22; 'header:User-Agent:1': 0.23; 'file.': 0.24; 'header:In-Reply- To:1': 0.27; 'point': 0.28; 'question:': 0.31; 'trivial': 0.31; 'file': 0.32; 'done.': 0.35; 'but': 0.35; 'there': 0.35; 'charset :us-ascii': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'called': 0.40; 'received:173': 0.61; 'name': 0.63; 'to,': 0.72; 'beats': 0.84; 'subject:Mystery': 0.84
Date Mon, 29 Apr 2013 12:53:32 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2
MIME-Version 1.0
To python-list@python.org
Subject Re: Mystery of module bindings!
References <201304291930.r3TJUTjc009818@pelican.ucsd.edu>
In-Reply-To <201304291930.r3TJUTjc009818@pelican.ucsd.edu>
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender ([173.12.184.235]) [173.12.184.235]:45950
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1165.1367268102.3114.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1367268102 news.xs4all.nl 15994 [2001:888:2000:d::a6]:50633
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:44523

Show key headers only | View raw


On 04/29/2013 12:30 PM, Peter Rowat wrote:
> 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?

That "fix" is indeed the way things are done.  Modules only know about what they import or create*.

The point of the startup file is to have things ready for interactive investigation -- if you use numpy *alot* then 
having it already there beats the heck out of typing `import numpy as np` every time you start the interpreter.

--
~Ethan~

*Unless you start playing with injection and stuff.

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


Thread

Re: Mystery of module bindings! Ethan Furman <ethan@stoneleaf.us> - 2013-04-29 12:53 -0700

csiph-web