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

Barry A. Warsaw bwarsaw@cnri.reston.va.us (Barry A. Warsaw)
1999年7月22日 14:33:57 -0400 (EDT)


>>>>> "M" == M <mal@lemburg.com> writes:

 M> Wouldn't a generic builtin for these kinds of things be
 M> better, e.g. a function returning a default value in case
 M> an exception occurs... something like:
 M> tryexcept(list.pop(), IndexError, default)
 M> which returns default in case an IndexError occurs. Don't think
 M> this would be much faster that the explicit try:...except:
 M> though...
Don't know if this would be better (or useful, etc.), but it could
possibly be faster than explicit try/except, because with try/except
you have to instantiate the exception object. Presumably tryexcept()
-- however it was spelled -- would catch the exception in C, thus
avoiding the overhead of exception object instantiation.
-Barry

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