Classes, OOP, Tkinter general comments and detailed questions...

Alex Martelli aleaxit at yahoo.com
Fri Apr 6 10:23:48 EDT 2001


"Ron Stephens" <rdsteph at earthlink.net> wrote in message
news:3ACBADAC.C7843F96 at earthlink.net...
    [snip]
> When he codes
>
> self.buttons=[]
> self.strings=[]
>
> does he just make this up??? There are no defined methods called buttons
> or strings that I now of, in the frame class. If he just makes them up,
> what in the world do they mean????

He's binding (or re-binding if they were previously bound) two attributes
of object 'self', one named 'buttons', one named 'strings'; each is bound
to a list-object that is initially empty.

You can 'create' new attributes of any instance object by using
assignment syntax in this way.  What the new attributes you create
MEAN depends of course on how your code will use them!


> When he says
>
> self.buttons.append([None]*(NUMCRITERIA+1))
>             self.strings.append([None]*NUMCRITERIA)
>         self.score=[None]*NUMOPTIONS
>
> what does ([None]*(NUMCRITERIA + 1)) mean???

The round-parentheses around the whole are just the syntax of the
call to method append of attribute buttons of object self.

> How can None times anything
> equal anything other than zero???

It's not "None times anything", it's a list times something.  It
means a new list constructed by concatenating that number of copies
of the list you are "multiplying".  Here, a list of NUMCRITERIA+1
items, all starting out as referring to None.

None itself does not support a multiplication operator, so trying
to multiply it by something would give an exception, not 'zero'.

> and is [None] a list ?????? I know, a dumb question....

Yes, [None] is a 1-element list, just as, say, [23], or ['ciao!'].
The bracket-syntax is a list-constructor.


Alex






More information about the Python-list mailing list