Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Namespaces are one honking great idea Date: Tue, 5 Jul 2016 13:47:41 +1000 Lines: 27 Message-ID: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577b1cc6$0$1584$c3e8da3$5496439d@news.astraweb.com> <577b2af3$0$1611$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de l9Ng/+Ys10SH6MSfg3vPAAmxDulj7hb9RMXZlaOUPM2w== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(even': 0.05; 'cc:addr :python-list': 0.09; 'builtins': 0.09; 'inserted': 0.09; 'module)': 0.09; 'namespace': 0.09; 'def': 0.13; 'file,': 0.15; 'importing': 0.15; '(do': 0.16; '.py': 0.16; '2016': 0.16; '999': 0.16; 'ah,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'namespace,': 0.16; 'namespace?': 0.16; 'out"': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Namespaces': 0.16; 'test():': 0.16; 'wrote:': 0.16; 'nested': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'work,': 0.21; '(the': 0.22; 'do.': 0.22; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'sense': 0.26; 'not.': 0.27; 'separate': 0.27; 'message-id:@mail.gmail.com': 0.27; 'resolution': 0.28; 'code': 0.30; 'push': 0.30; 'class': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'tue,': 0.34; 'file': 0.34; 'received:google.com': 0.35; 'necessary.': 0.35; 'path': 0.35; 'but': 0.36; 'should': 0.36; 'modules': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'does': 0.39; 'your': 0.60; 'real': 0.62; 'jul': 0.72; '"just': 0.84; 'chrisa': 0.84; 'question!': 0.84; '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:from:date:message-id:subject:cc; bh=y/9vTNPWqUTFxVAF1c+1gtf6h7nSCvHZ/E8S/65vJK8=; b=SzXDYkXF8GdGSSBx/gwtbW0CW0fcLKGJTp50txa+c/xVKB5hruvXjzmXaDd3wJTtt9 ozGjsi6xUjHNpQ8pQ2t0np5Hrfd/VU3qBj0aePC15HisVNAkuB2oxBS2GUybr/6WKiUO kELKxWooNMRzKUxEh+Z+rk/cMp6dgnHMure0HouEBJg38+axtx5OzTBadjeN3NftcMDR OU5JpXEWrHc4erXGOuoZIk6RbSqzTEvkKjls/3YeSBr/fCQtCxpAI+q5DqeGRFv5wpBs XlJncPw+/5+mT0MOikphR4Z4bYoorL1nmgek8gUJWj8z+9qQKmhzf50uq6N5+SJewey4 Wc1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:cc; bh=y/9vTNPWqUTFxVAF1c+1gtf6h7nSCvHZ/E8S/65vJK8=; b=fPRl0awYpEPPkuZGSr3m40m/od01wgPxHvV1p5CHt3h87WAZ4Emx5oFpyHpoByj6vz LUyeunzNeqNKDG+gOum8n/9+OVhe6HxxCYYte5jXF3V9Id/b/RzMog8B4nfNzfqQTi83 pGDtHePqx2Z/DRffcxhNOzQu/SK/NtXSYhae6mHxGBxw6hGsERXNuH3e4k+0w7keO7jz dqtACpjdLg2EDZDwfu64w/IlGIuH6MWd9Ow6SU8XT3A7LI19ykP0N+a5d6+kZWrPfR46 BVN/8QXCu/mkd0zY303Z3ZnVLb+wg0Xz+ALdwXhInzOKO2n8ZQga+GyLAkbIoAeu5Dd+ VOPw== X-Gm-Message-State: ALyK8tJ120C8De3352Vu4CpyZAEDQedFWM4FpFDPYj+4/Rwp5IxV4/a28JL1sbl+3AQbFlJYo/DirhfXC0vZ8Q== X-Received: by 10.28.44.131 with SMTP id s125mr12998224wms.61.1467690462445; Mon, 04 Jul 2016 20:47:42 -0700 (PDT) In-Reply-To: <577b2af3$0$1611$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577b1cc6$0$1584$c3e8da3$5496439d@news.astraweb.com> <577b2af3$0$1611$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:111094 On Tue, Jul 5, 2016 at 1:35 PM, Steven D'Aprano wrote: >> If you push your code into a separate .py file, you can reference the >> original module by importing it. Is that also the normal way to use >> "outer" functions etc from inside a namespace? > > Good question! > > With the current implementation, importing should work, but it's not > necessary. The surrounding module (the real .py module) is inserted into > the name resolution path of functions: > > py> x = 999 > py> @namespace.Namespace > ... class Test: > ... def test(): > ... print(x) > ... > py> Test.test() > 999 Ah, fascinating. This does break the "just unindent and move to a new file if you want to break it out" equivalency, but it does make sense - it's a *nested* namespace, which modules (even in a package) are not. So you have the outer namespace acting pretty much the way builtins do. (Do nested namespaces work?) ChrisA