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


Groups > comp.lang.python > #10466 > unrolled thread

Re: NoneType and new instances

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2011-07-28 11:12 -0600
Last post2011-07-29 11:20 +1000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: NoneType and new instances Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-28 11:12 -0600
    Re: NoneType and new instances Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-29 11:20 +1000

#10466 — Re: NoneType and new instances

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-07-28 11:12 -0600
SubjectRe: NoneType and new instances
Message-ID<mailman.1579.1311873164.1164.python-list@python.org>
On Thu, Jul 28, 2011 at 9:39 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
> Why is NoneType unable to produce a None instance?  I realise that None is a
> singleton, but so are True and False, and bool is able to handle returning
> them:

The bool constructor works (actually just returns one of the existing
singletons) so that you can do things like this:

truth_value = bool(x + 5)
return my_dict[truth_value]

Why would you ever need to instantiate NoneType?

[toc] | [next] | [standalone]


#10494

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2011-07-29 11:20 +1000
Message-ID<4e320af4$0$29966$c3e8da3$5496439d@news.astraweb.com>
In reply to#10466
Ian Kelly wrote:

> Why would you ever need to instantiate NoneType?


Well, you probably wouldn't deliberately, but if you have code like this:


types = [type(x) for x in list_of_objects]
# later on...
for t in types:
    instance = t()
    do_something_with(instance)


it would be nice if it didn't explode when list_of_objects contains None.


-- 
Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web