Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50390
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Recursive class | can you modify self directly? |
| Date | 2013-07-10 15:33 -0400 |
| References | <61751485-a298-403e-8b44-be7cf2504f0e@googlegroups.com> <42591572-a09b-4362-8da2-d083c6424b4a@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4547.1373484820.3114.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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