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


Groups > comp.lang.python > #76440

Re: Module-level functions and the module type

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
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; 'explicit': 0.07; 'level,': 0.07; 'problem:': 0.07; 'attributes': 0.09; 'convention,': 0.09; 'correspond': 0.09; 'currently,': 0.09; 'subject:module': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'globals': 0.16; 'len(c)': 0.16; 'materially': 0.16; 'namespace,': 0.16; 'subject:type': 0.16; 'trivially': 0.16; 'unnecessary.': 0.16; 'variables,': 0.16; 'which,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'bit': 0.19; 'module': 0.19; "python's": 0.19; 'example': 0.22; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'refers': 0.24; 'decide': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'possibly': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'that.': 0.31; "d'aprano": 0.31; 'implicit': 0.31; 'object.': 0.31; 'steven': 0.31; 'class': 0.32; 'third': 0.33; 'subject:the': 0.34; 'could': 0.34; 'agree': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'c++': 0.36; 'doing': 0.36; 'level': 0.37; 'requiring': 0.38; 'that,': 0.38; 'how': 0.40; 'even': 0.60; 'reserved': 0.61; 'kind': 0.63; 'decided': 0.64; 'more': 0.64; 'different': 0.65; 'special': 0.74; 'entry,': 0.84; "it'd": 0.84; 'local,': 0.84; 'to:none': 0.92
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=FuMi+gPJdQQo9NqBh3D+Zlp8wrN/AfV69jATbmnrc34=; b=tj4bblgK9PIpei3/X4UUQ/+dGtlXZaLYYJY6IxIXdLM5YSjBsADSfqyaVK/1SQbPrW Pl00sz+TEgdPT7/46/NamC9PUYHAT2hpF2HP6pRPxXGf8xn8Ff5ow5eQRRvjGOCKNOFb eCTnRvJrfWwFN85DWtjfTbtIbhxmYpSLwRqgnXUTAlBuPGjSBRFEujEQvZFot1e1LcZZ s6schFr4aLQtQuPRRntypY6unvxSGqRCiVRFMCQusFfx9/m09nzfO/SKyywsDrHjwGZZ 41YtN9zmfYhkVuC/uADt5SapyoMYZ+Hh/S2slyYHMKhUz55l3hVOvpawHAhkF24TT4H4 tiKg==
MIME-Version 1.0
X-Received by 10.50.30.72 with SMTP id q8mr78496091igh.14.1408292406660; Sun, 17 Aug 2014 09:20:06 -0700 (PDT)
In-Reply-To <53f0d167$0$29976$c3e8da3$5496439d@news.astraweb.com>
References <mailman.13070.1408288560.18130.python-list@python.org> <53f0d167$0$29976$c3e8da3$5496439d@news.astraweb.com>
Date Mon, 18 Aug 2014 02:20:06 +1000
Subject Re: Module-level functions and the module type
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <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 <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.13075.1408292414.18130.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1408292414 news.xs4all.nl 2967 [2001:888:2000:d::a6]:47627
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:76440

Show key headers only | View raw


On Mon, Aug 18, 2014 at 1:59 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> But inside class methods we have a problem:
>
> class X:
>     def method():
>         a = b + c
>
> We can trivially decide on a rule that a must be a local, but how about b
> and c? Are they globals or attributes of the instance? Python decided on
> giving globals (well, actually nonlocals) priority, and requiring an
> explicit self, so we can write this:
>
>     def method(self):
>         a = self.b + len(c)
>
> instead of this:
>
>     def method():
>         locals.a = b + globals.len(globals.c)

I agree with this, and the C++ way of doing things is fraught with
peril. The only way it could even possibly work is with fully-declared
instance variables, and that's something Python's not going for :)

However, there's no particular reason not to have 'self' as a special
name. It's already pretty much reserved for that by convention, so
this would just mean that, in a module with an explicit metaclass,
'self' refers to the module object. You'd get something like this:

def method():
    a = self.b + len(c)

which, after all, isn't materially different from your third entry, in
that both of them need some kind of implicit namespace, just as your
explicit 'this' example from above does.

Since this would then also be at module level, it would be reasonable
for 'global x' to correspond to 'self.x', which is something that
would require a bit more language support. Currently, the version I
demonstrated has an extra level of namespacing, which is completely
unnecessary. It'd be nice to be able to unify all of that.

ChrisA

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


Thread

Module-level functions and the module type Chris Angelico <rosuav@gmail.com> - 2014-08-18 01:15 +1000
  Re: Module-level functions and the module type Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-18 01:59 +1000
    Re: Module-level functions and the module type Chris Angelico <rosuav@gmail.com> - 2014-08-18 02:20 +1000

csiph-web