Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10482 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2011-07-29 07:16 +1000 |
| Last post | 2011-07-29 11:29 +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.
Re: NoneType and new instances Chris Angelico <rosuav@gmail.com> - 2011-07-29 07:16 +1000
Re: NoneType and new instances Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-29 11:29 +1000
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-07-29 07:16 +1000 |
| Subject | Re: NoneType and new instances |
| Message-ID | <mailman.1594.1311887809.1164.python-list@python.org> |
On Fri, Jul 29, 2011 at 7:03 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
> I'll use a lambda to get around it, but that's not very elegant. Why
> shouldn't NoneType be able to return the singleton None?
Why a lambda?
def ThisFunctionWillReturnNone():
pass
Although, since the returning of None is crucial to it, it'd probably
be better to explicitly "return None". But minimalist useful functions
are amusing.
ChrisA
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2011-07-29 11:29 +1000 |
| Message-ID | <4e320cfd$0$29979$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #10482 |
Chris Angelico wrote:
> On Fri, Jul 29, 2011 at 7:03 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
>> I'll use a lambda to get around it, but that's not very elegant. Why
>> shouldn't NoneType be able to return the singleton None?
>
> Why a lambda?
>
> def ThisFunctionWillReturnNone():
> pass
This is a good use-case for a lambda. Ethan's use-case is a dict of
constructors:
fielddef = { 'empty':some_func, 'null':some_func }
There's no need to expose the constructor outside of the dict, hence:
fielddef = { 'empty': str, 'null': lambda: None }
does the job. No need for a top-level named function.
--
Steven
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web