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


Groups > comp.lang.python > #50390

Re: Recursive class | can you modify self directly?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.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.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'parameters': 0.04; 'argument': 0.05; 'classes,': 0.05; 'modify': 0.07; 'modifying': 0.07; 'convention,': 0.09; 'namespace': 0.09; 'parameter': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'bug': 0.12; 'jan': 0.12; 'argument,': 0.16; 'argument.': 0.16; 'object)': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'relevance': 0.16; 'subject:class': 0.16; 'wrote:': 0.18; '(not': 0.18; 'variable': 0.18; 'passing': 0.19; '(the': 0.22; 'memory': 0.22; 'header:User-Agent:1': 0.23; 'exists': 0.24; 'refers': 0.24; 'requirement.': 0.24; 'initial': 0.24; 'somewhere': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'am,': 0.29; 'points': 0.29; "doesn't": 0.30; 'code': 0.31; "skip:' 10": 0.31; 'names.': 0.31; 'object.': 0.31; 'yes.': 0.31; 'class': 0.32; 'another': 0.32; 'knowledge': 0.35; 'definition': 0.35; 'objects': 0.35; 'but': 0.35; 'there': 0.35; 'object,': 0.36; 'method': 0.36; 'subject:?': 0.36; 'being': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'does': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:x 10': 0.40; 'affect': 0.61; 'received:173': 0.61; 'first': 0.61; 'name': 0.63; 'different': 0.65; 'to,': 0.72; 'functions)': 0.84; 'received:fios.verizon.net': 0.84; 'subject:self': 0.84; 'subject:you': 0.87
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Recursive class | can you modify self directly?
Date Wed, 10 Jul 2013 15:33:25 -0400
References <61751485-a298-403e-8b44-be7cf2504f0e@googlegroups.com> <42591572-a09b-4362-8da2-d083c6424b4a@googlegroups.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-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7
In-Reply-To <42591572-a09b-4362-8da2-d083c6424b4a@googlegroups.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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4547.1373484820.3114.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1373484820 news.xs4all.nl 15914 [2001:888:2000:d::a6]:44967
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:50390

Show key headers only | View raw


On 7/10/2013 4:58 AM, Russel Walker wrote:

> There is the name x and the class instance (the object) which exists
> somewhere in memory that x points to. self is just another name that
> points to the same object (not self in general but the argument
> passed to the self parameter when a method is called). However if the
> code inside the method reassigns self to some other object, it
> doesn't change the fact that x still refers to the original object.
> So self is just a local variable (an argument).

Yes, parameters *names* are the initial local names of the function. 
Calling the first parameter of instancemethods 'self' is a convention, 
not a requirement.

 > The name self has no
> relevance to to the name x other than the fact that they point to the
> same object. So reassigning self has no effect on x. But modifying
> the object that self points to, does affect x because it points to
> the same object. Is this correct?

Yes. Multiple names for one objects are 'aliases'. Being able to modify 
a object with multiple names in different namespaces is both a boon and 
bug bait.

> So when you call x.somemethod() it's not passing x as the self

Python does not pass'x': it is 'call-by-object', not 'call-by-name'.

> argument, it's actually passing the object that x points to as the
> self argument. And that object has know knowledge of the fact that x
> points to it, or does it?

Some objects (modules, classes, functions) have definition names 
(.__name__ attributes) that are used in their representations (as in 
tracebacks). But they have no knowledge of their namespace names.



-- 
Terry Jan Reedy

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


Thread

Recursive class | can you modify self directly? Russel Walker <russ.pobox@gmail.com> - 2013-07-09 15:01 -0700
  Re: Recursive class | can you modify self directly? Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-09 16:18 -0600
  Re: Recursive class | can you modify self directly? Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-09 16:20 -0600
    Re: Recursive class | can you modify self directly? Russel Walker <russ.pobox@gmail.com> - 2013-07-10 02:00 -0700
  Re: Recursive class | can you modify self directly? Dave Angel <davea@davea.name> - 2013-07-09 18:30 -0400
  Re: Recursive class | can you modify self directly? Ethan Furman <ethan@stoneleaf.us> - 2013-07-09 15:19 -0700
  Re: Recursive class | can you modify self directly? Russel Walker <russ.pobox@gmail.com> - 2013-07-10 01:58 -0700
    Re: Recursive class | can you modify self directly? Terry Reedy <tjreedy@udel.edu> - 2013-07-10 15:33 -0400
      Re: Recursive class | can you modify self directly? Russel Walker <russ.pobox@gmail.com> - 2013-07-10 13:09 -0700
  Re: Recursive class | can you modify self directly? Russel Walker <russ.pobox@gmail.com> - 2013-07-10 15:50 -0700
    Re: Recursive class | can you modify self directly? Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-10 17:39 -0600

csiph-web