Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '(especially': 0.07; 'pep': 0.09; 'try:': 0.09; 'python': 0.11; 'elsewhere,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'skip:g 50': 0.16; 'discussions': 0.16; 'exception': 0.16; 'to:name:python-list@python.org': 0.22; 'subject:Code': 0.24; 'versions': 0.24; 'defined': 0.27; 'function': 0.29; 'message- id:@mail.gmail.com': 0.30; 'subject:the': 0.34; 'except': 0.35; 'received:google.com': 0.35; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'new': 0.61; 'developed': 0.63; 'different': 0.65; 'details': 0.65; 'subject:Day': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=7lBscXoIzXA0AE8t1WhxfrosNX7AXvOQw1haxClYSEY=; b=rlp0F/pVaEfFZFd9b7DXF1muHldUOyOwH3bCQWF9z5P435WoRam8G6cc8oOwmc8VDQ vVHmhXDFS46CmarWNtzpuEVAgEC1lSOCemi/N88inANYbnvMxMFlQTKL5iKp5WwwQbDL 9VFiahsabxwEsNxneJ5Oh239JVcfgvytr9uCa+MnSx5DCahQI7SBviW4YyY8OZDA3KRp N1BvZbYpejWHvXI4B6Xa/BPpbqWgDCM7EnJm0HlxXUoQwnhAQYuNXhOZFOlKhHG05cy/ LleG6y1oCMdE5EqCqGKxeDJA+nEM7Hrh/Cjab9gOyCeKdaevTnnNyg627+OqSV1U0GXl bQ6Q== MIME-Version: 1.0 X-Received: by 10.68.200.74 with SMTP id jq10mr4705480pbc.169.1392742035271; Tue, 18 Feb 2014 08:47:15 -0800 (PST) Date: Wed, 19 Feb 2014 03:47:15 +1100 Subject: Bad Code Snippet of the Day From: Chris Angelico To: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392742039 news.xs4all.nl 2955 [2001:888:2000:d::a6]:37892 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66637 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