Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Unable to access module attribute with underscores in class method, Python 3 Date: Sat, 9 Jan 2016 03:16:35 +1100 Lines: 23 Message-ID: References: <568fded7$0$1608$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de fExNrBzV7yVJ6KVrgL76MQ92mwyvku0EU1kP5O89+sVQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'cc:addr:python-list': 0.09; 'subject:method': 0.09; 'subject:module': 0.09; 'underscore': 0.09; 'jan': 0.11; 'def': 0.13; 'subject: \n ': 0.15; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:access': 0.16; 'subject:class': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'sat,': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'that.': 0.30; 'run': 0.33; 'class': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'received:google.com': 0.35; 'could': 0.35; 'asking': 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'subject:with': 0.40; 'chrisa': 0.84; 'absolutely': 0.88; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Fy2fFPDwwkl6MY6bJy4QWh37wcMaREsFddYOdrdQm30=; b=x5Rq1XwU9hIFcV12dyygMtDAcO9nkUu/ny1ZyWRUlFnhIwh4SI9ufSvejksilb5E+O xPnC9ZhvKG7U9VoJDlNacl/27dmznDgNa51eEORg7lA8Fx/XbPyuc/kmAXEzUR8+IhHS qrkEx/IGLVRndxQrrP0ab9QppkduOSb0ixctwCZOa5Npqgotxl5fzFbpx+0cj+IU87hF o6w++suQdMKW/DbpihKW3igmyBewXEk6p4mB9hsaHCIs2USVu/bT++CcjTSjacANPa1Y SU6y9h7v0umHqScsFS6v1W+5vBEoNwUrEcBSgUbZ5e71ApDslD+8P2bvBhFH/LYcn+9I iw0Q== X-Received: by 10.50.134.227 with SMTP id pn3mr13750093igb.13.1452269795440; Fri, 08 Jan 2016 08:16:35 -0800 (PST) In-Reply-To: <568fded7$0$1608$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101382 On Sat, Jan 9, 2016 at 3:07 AM, Steven D'Aprano wrote: > If you absolutely insist that you must must must continue to use a double > underscore name, you could also try this: > > py> __a = 1 > py> class Test: > ... def method(self): > ... x = eval("__a") > ... print(x) > ... > py> Test().method() > 1 > > > But don't do that. Seriously? You consider that less bad than globals()["__a"]? But all of this is craziness to support craziness. It's not asking which inmate should run the asylum - it's asking which of my multiple personalities should be elected fourteen-year-old queen. ChrisA