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: 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: <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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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