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

From Peter Otten <__peter__@web.de>
Subject Re: Statement evals as False in my IDE and True elsewhere
Date 2014-01-31 00: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>
Newsgroups comp.lang.python
Message-ID <mailman.6177.1391123287.18130.python-list@python.org> (permalink)

Show all headers | 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