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


Groups > comp.lang.python > #65066

Re: Statement evals as False in my IDE and True elsewhere

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'attribute': 0.07; 'error:': 0.07; 'rename': 0.07; 'builtin': 0.09; 'namespace': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; '"from': 0.16; '(both': 0.16; '__builtin__': 0.16; 'hint:': 0.16; 'imports': 0.16; "module's": 0.16; 'numpy': 0.16; 'pylab': 0.16; 'pythonic': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'thursday,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'seems': 0.21; '>>>': 0.22; 'code,': 0.22; 'import': 0.22; 'print': 0.22; 'this?': 0.23; 'header:User- Agent:1': 0.23; 'module,': 0.24; 'visible': 0.24; 'first,': 0.26; 'this:': 0.26; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; 'fixed': 0.29; 'thus': 0.29; "i'm": 0.30; 'getting': 0.31; 'follows': 0.31; 'thanks!': 0.32; 'skip:_ 10': 0.34; 'case,': 0.35; 'but': 0.35; 'there': 0.35; 'false': 0.36; 'module.': 0.36; 'doing': 0.36; 'january': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'remove': 0.60; 'most': 0.60; 'first': 0.61; 'here:': 0.62; 'skip:n 10': 0.64; '30,': 0.65; "'all'": 0.84; 'otten': 0.84; 'subject:Statement': 0.91; 'subject:True': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Statement evals as False in my IDE and True elsewhere
Date Fri, 31 Jan 2014 00:08:08 +0100
Organization None
References <a543e1a5-ef00-42b0-96df-5bf9ee8ac74c@googlegroups.com> <mailman.6169.1391120094.18130.python-list@python.org> <13a1aca8-a246-4618-925f-05ebf6c2e950@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084acba.dip0.t-ipconnect.de
User-Agent KNode/4.7.3
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6177.1391123287.18130.python-list@python.org> (permalink)
Lines 51
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391123287 news.xs4all.nl 2921 [2001:888:2000:d::a6]:36909
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65066

Show key headers only | View raw


CM wrote:

> On Thursday, January 30, 2014 5:14:57 PM UTC-5, Peter Otten wrote:
> 
>> Hint:
>> 
>> >>> def demo():
>> ...     fake_data = ['n/a', 'n/a', 'n/a', 'n/a', '[omitted]', '12']
>> ...     fake_result = not all(i == '[omitted]' for i in fake_data)
>> ...     print 'This is fake result: ', fake_result
>> 
>> >>> demo()
>> This is fake result:  True
>> 
>> >>> from numpy import all
>> >>> demo()
>> This is fake result:  False
> 
> That's brilliant, thanks!  Now I'm just a bit unsure of what to do about
> it.  First, I don't actually have the line "from numpy import all" in that
> module's code, although I have imports of numpy; I think it is getting
> brought in through Matplotlib's pylab module, which I do import in that
> module.
> 
> In any case, what's the most Pythonic way to deal with this?  My first
> thought was to create the old all function and rename it so there would be
> no conflict:
> 
> (both of what follows taken from answers here:
> http://stackoverflow.com/questions/18774388/re-import-aliased-shadowed-
python-built-in-methods)
> 
> builtin_all = __builtins__.all
> 
> but I got the error:
> 
> AttributeError: 'dict' object has no attribute 'all'
> 
> So I wound up doing this:
> 
> from __builtin__ import *
> 
> which fixed the problem...but seems less than optimal, because what if I
> wanted to have numpy's all still in play?

import numpy # you can now use numpy's all as numpy.all(...)
del all      # remove numpy's all from your module's global namespace and
             # thus make the builtin visible again


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


Thread

Statement evals as False in my IDE and True elsewhere CM <cmpython@gmail.com> - 2014-01-30 14:04 -0800
  Re: Statement evals as False in my IDE and True elsewhere Peter Otten <__peter__@web.de> - 2014-01-30 23:14 +0100
    Re: Statement evals as False in my IDE and True elsewhere CM <cmpython@gmail.com> - 2014-01-30 14:48 -0800
      Re: Statement evals as False in my IDE and True elsewhere Chris Angelico <rosuav@gmail.com> - 2014-01-31 09:55 +1100
        Re: Statement evals as False in my IDE and True elsewhere CM <cmpython@gmail.com> - 2014-01-30 15:02 -0800
      Re: Statement evals as False in my IDE and True elsewhere Peter Otten <__peter__@web.de> - 2014-01-31 00:08 +0100
      Re: Statement evals as False in my IDE and True elsewhere Terry Reedy <tjreedy@udel.edu> - 2014-01-31 00:05 -0500
      Re: Statement evals as False in my IDE and True elsewhere Chris Angelico <rosuav@gmail.com> - 2014-01-31 16:07 +1100
  Re: Statement evals as False in my IDE and True elsewhere Chris Angelico <rosuav@gmail.com> - 2014-01-31 09:25 +1100
    Re: Statement evals as False in my IDE and True elsewhere CM <cmpython@gmail.com> - 2014-01-30 15:00 -0800
      Re: Statement evals as False in my IDE and True elsewhere Chris Angelico <rosuav@gmail.com> - 2014-01-31 10:25 +1100
      Re: Statement evals as False in my IDE and True elsewhere Terry Reedy <tjreedy@udel.edu> - 2014-01-31 00:09 -0500

csiph-web