[Python-Dev] I'd like list.pop to accept an optional second

Jim Fulton jim@digicool.com
1999年7月22日 11:44:22 -0400


Gordon McMillan wrote:
>> Jim Fulton wrote:
>> > Gordon McMillan wrote:
> > >
> > > Then how do I get the old behavior?
> >
> > Just pass 0 or 1 argument.
> >
> > >(I've been known to do odd
> > > things - like change behavior based on the number of args - in
> > > extension modules, but this ain't an extension).
> >
> > It *is* a built-in method. It will be handled just like
> > dictionaries handle the second argument to get.
>> d.get(nonexistantkey) does not throw an exception, it returns None.

Oops, I'd forgotten that.
> If list.pop() does not throw an exception when list is empty, it's
> new behavior.
>> Which are you asking for:
> breaking code that expects IndexError

No.
> Violating Pythonic expectations by, in effect, creating 2 methods
> list.pop(void)
> list.pop(default_return)

Yes, except that I disagree that this is non-pythonic.
Jim
--
Jim Fulton mailto:jim@digicool.com Python Powered! 
Technical Director (888) 344-4332 http://www.python.org 
Digital Creations http://www.digicool.com http://www.zope.org 
Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission. Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of 500ドル damages/incident, 1500ドル for
repeats.

AltStyle によって変換されたページ (->オリジナル) /