Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #15743
| References | (4 earlier) <4EC2B656.7050902@sequans.com> <0601B8C7-9AEF-443A-A149-0F7D356345EF@gmail.com> <CAPTjJmrP7fMg9UfxdsR=5j6EW4yFKf8gR4xYQD5zDwMUVxdmjw@mail.gmail.com> <F8266E63-F932-4216-9E33-8333C1D62E43@gmail.com> <CAPTjJmofCYDy5rLPzCJPNMj5qM_KAc9606RmLKAtcaySjwf92w@mail.gmail.com> |
|---|---|
| Date | 2011-11-15 21:42 +0000 |
| Subject | Re: suppressing import errors |
| From | Arnaud Delobelle <arnodel@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2752.1321393344.27778.python-list@python.org> (permalink) |
On 15 November 2011 21:34, Chris Angelico <rosuav@gmail.com> wrote: > On Wed, Nov 16, 2011 at 8:20 AM, David Riley <fraveydank@gmail.com> wrote: >> Comparisons to singletons like None should always be done with >> 'is' or 'is not', never the equality operators. >> >> Also, beware of writing "if x" when you really mean "if x is not None" >> -- e.g. when testing whether a variable or argument that defaults to >> 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! > > It's probably quicker to execute "if x is None" than "if x" > (presumably the former just compares the two pointers). On the other > hand, it's more compact to leave off the "is None". And on the > gripping hand, neither "quicker to execute" nor "more compact" equates > to "more Pythonic". It's idiomatic to write "x is None" when you want to know whether x is None. -- Arnaud
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: suppressing import errors Arnaud Delobelle <arnodel@gmail.com> - 2011-11-15 21:42 +0000
csiph-web