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


Groups > comp.lang.python > #66637

Bad Code Snippet of the Day

Date 2014-02-19 03:47 +1100
Subject Bad Code Snippet of the Day
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.7119.1392742039.18130.python-list@python.org> (permalink)

Show all headers | View raw


I call this "Russian Exception Roulette". It came about because of
some discussions on python-ideas regarding the new PEP 463 and
exception handling.

try:
    exc = getattr(__builtins__,random.choice(list(filter(lambda x:
x.endswith("Error"),dir(__builtins__)))))
    f()
except exc:
    print("You win!")


Given a function f(), defined elsewhere, what will this do?

Note that this was developed on Python 3.4, and some of the details
may be different on other versions (especially 2.x).

ChrisA

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Bad Code Snippet of the Day Chris Angelico <rosuav@gmail.com> - 2014-02-19 03:47 +1100
  Re: Bad Code Snippet of the Day Rick Johnson <rantingrickjohnson@gmail.com> - 2014-02-18 13:10 -0800
    Re: Bad Code Snippet of the Day Chris Angelico <rosuav@gmail.com> - 2014-02-19 08:21 +1100

csiph-web