Question about code writing '% i, callback'
Ian Kelly
ian.g.kelly at gmail.com
Tue Dec 1 10:53:40 EST 2015
On Mon, Nov 30, 2015 at 7:44 PM, Dennis Lee Bieber
<wlfraed at ix.netcom.com> wrote:
> On 2015年11月30日 10:55:23 -0800 (PST), fl <rxjwg98 at gmail.com> declaimed
> the following:
>>>Thanks Ian. I created the class because I want to use the original example
>>line
>>>> UI.Button("button %s" % i, callback)
>>>>Is there another way to use the above line without my class definition?
>>I do feel that my created class does not match well with the above line
>>because the first item "button %s" does not fit __self__ in the class.
>> The first item passed to a method call is the instance object... In
> this case, whatever "UI" is bound to.
>> If it helps, think of
>> UI.Button("string", callback)
> as
> Button(UI, "string", callback)
This is only correct if "UI" is bound to an instance of a class and
"Button" is a method of that class. If UI is a class itself or a
module, then those are not equivalent.
More information about the Python-list
mailing list