Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #15751
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Alan Meyer <ameyer2@yahoo.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: suppressing import errors |
| Date | Tue, 15 Nov 2011 17:59:12 -0500 |
| Organization | A noiseless patient Spider |
| Lines | 40 |
| Message-ID | <4EC2EEC0.2090806@yahoo.com> (permalink) |
| References | <CAC82khmG+zH3Cd5pRfou+0FED18MHfizLzJL4EM+V+Pw+q17+w@mail.gmail.com> <CALvWhxvc=Ng28YeiL0Onv9YCixfQtOqgLENWJqYgoRSYvo_juA@mail.gmail.com> <CAC82khn3WBjXY7podVq6RX0d0j38w1vbtN3fNOCSGLcu2X_jOw@mail.gmail.com> <D97140E4-9B09-4EAE-BB92-0F038FCDBA5A@gmail.com> <4EC2B656.7050902@sequans.com> <0601B8C7-9AEF-443A-A149-0F7D356345EF@gmail.com> <CAPTjJmrP7fMg9UfxdsR=5j6EW4yFKf8gR4xYQD5zDwMUVxdmjw@mail.gmail.com> <mailman.2750.1321392038.27778.python-list@python.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Info | mx04.eternal-september.org; posting-host="cXfoUdE2tOmL54C/tFXK/Q"; logging-data="14534"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+KtesB2WTCAgD0Z1RhdRx0" |
| User-Agent | Mozilla/5.0 (Windows NT 6.0; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 |
| In-Reply-To | <mailman.2750.1321392038.27778.python-list@python.org> |
| Cancel-Lock | sha1:z4MxZJa8rboGp1kXu507b1+soas= |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:15751 |
Show key headers only | View raw
On 11/15/2011 4:20 PM, David Riley wrote:
...
> None was set to some other value. The other value might have a type
> (such as a container) that could be false in a boolean context!
>
> Obviously, that last bit doesn't apply to modules; they're not going to evaluate as False in general. I just bristle when I see people writing "if x" when they really mean "if x is not None", perhaps because it's not The Right Way(tm)? It mostly comes down to aesthetics, I guess. Write what you really mean.
Actually Dave, as your quote from PEP 8 says, the difference is real.
It's not just aesthetics.
Consider this:
x = None
if x:
print('if x == true')
else:
print('if x == false')
if x is None:
print('x is None == true')
else:
print('x is none == false')
y = ''
if y:
print('if y == true')
else:
print('if y == false')
if y is None:
print('y is None == true')
else:
print('y is none == false')
The result is:
if x == false
x is None == true
if y == false
y is none == false
Alan
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: suppressing import errors David Riley <fraveydank@gmail.com> - 2011-11-15 16:20 -0500
Re: suppressing import errors Alan Meyer <ameyer2@yahoo.com> - 2011-11-15 17:59 -0500
Re: suppressing import errors David Riley <fraveydank@gmail.com> - 2011-11-15 18:15 -0500
csiph-web