[Tutor] Self, Scopes and my unbelievable muddleheadedness.

doug shawhan doug.shawhan at gmail.com
Thu Oct 26 21:18:44 CEST 2006


On 10/25/06, Luke Paireepinart <rabidpoobear at gmail.com> wrote:
>
>
> >
> > I'm sure this is so obvious that a crack-addled tapeworm head down in
> > a bucket of stupid could understand it, unfortunately, I'm not quite
> > at that level today. Sorry.
> Uh, I don't understand why you're passing Fields to the functions but
> then putting the value in self.Fields...
> but we'll ignore that for now :)


http://www.penzilla.net/tutorials/python/modules/

I explain my  confusion more coherently in my reply to Mr. Gald. :-)

The problem it sounds like you're having is that you think that passing
> lists to functions copies them,
> when in fact it just creates a reference to them.
> Take this, for example:



Close! I thought that "self" would somehow automagically create a copy of
the list, leaving a global intact. I am disillusioned.


>>> def append_five(alist):
>     alist.append(5)
> >>> a = [1,2,3,4]
> >>> append_five(a)
> >>> a
> [1, 2, 3, 4, 5]
> >>> append_five(a)
> >>> a
> [1, 2, 3, 4, 5, 5]



Which answers my question "why is my list of dictionaries turning in to a
list with a dictionary with a list of dictionaries therein! :-)

Other than that,
> Maybe you think self is used for something other than what it's intended
> to be used for...
> but I can't be sure.


Again, see my reply to Mr. Gald. I am starting to get my head around "self".
I searched usenet for explanations, apparently I'm not the only one. :-). It
seems to be pretty simple, for most. I'm reminded of learning to solve for
polynomials or diagram sentences: It's elementary to some and completely
obtuse to others, depending on mindset and experience.


I'm sure someone else can give you a good example.
> I, however, have to run.
> HTH,
> -Luke



Thanks! I appreciate it!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061026/bbf31203/attachment.html 


More information about the Tutor mailing list