Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66642
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; '(especially': 0.07; 'exception,': 0.09; 'pep': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'try:': 0.09; 'python': 0.11; 'jan': 0.12; 'elsewhere,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'skip:g 50': 0.16; 'discussions': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'subject:Code': 0.24; 'versions': 0.24; 'asking': 0.27; 'defined': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'raise': 0.29; 'prints': 0.31; 'subject:the': 0.34; 'except': 0.35; 'to:addr:python-list': 0.38; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'is.': 0.60; 'new': 0.61; 'received:173': 0.61; 'developed': 0.63; 'different': 0.65; 'details': 0.65; "'you": 0.84; 'received:fios.verizon.net': 0.84; 'subject:Day': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: Bad Code Snippet of the Day |
| Date | Tue, 18 Feb 2014 15:41:53 -0500 |
| References | <CAPTjJmqAAG+oxKKq=fDEA4bDHTcDO5dXZbJgR3VK98fg9xwC1Q@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | pool-173-75-254-207.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 |
| In-Reply-To | <CAPTjJmqAAG+oxKKq=fDEA4bDHTcDO5dXZbJgR3VK98fg9xwC1Q@mail.gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7122.1392756159.18130.python-list@python.org> (permalink) |
| Lines | 26 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1392756159 news.xs4all.nl 2870 [2001:888:2000:d::a6]:50957 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:66642 |
Show key headers only | View raw
On 2/18/2014 11:47 AM, Chris Angelico wrote:
> 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?
I am not sure what you are asking or what your point is. If f happens to
raise the randomly selected exception, it prints 'You win!', otherwise
it does nothing.
> Note that this was developed on Python 3.4, and some of the details
> may be different on other versions (especially 2.x).
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Bad Code Snippet of the Day Terry Reedy <tjreedy@udel.edu> - 2014-02-18 15:41 -0500 Re: Bad Code Snippet of the Day Roy Smith <roy@panix.com> - 2014-02-18 20:13 -0500
csiph-web