[Tutor] question about OOP (or just grammer thing) ?
Lloyd Kvam
pythontutor@venix.com
Fri, 28 Jun 2002 09:20:12 -0400
def myfunc( **kwargs)
is the python syntax (grammar) for collecting all of the key word arguments.
myfunc(len=1,width=3,units='cm') specifies three keyword (labeled) arguments.
The actual function will receive those arguments as a dictionary with the
name kwargs. The ** signals python to collect the keyword arguments into a
dictionary.
I can't say much about the Tkinter processing specifics, but you can see that this
provides a convenient mechanism for packaging long "lists" of arguments.
Geonjae Lee wrote:
> Hi I'm a python newbie.
> I'm studying Tkinter.
> And All I know about programming language was C.
> That means I'm also not used to the OOP concept.
>
> ==================================================================
>
> from Tkinter import *
>
> class HelloButton(Button):
> def __init__(self, parent=None, **config):
> Button.__init__(self, parent, config)
> self.pack()
> self.config(command=self.callback)
>
> def callback(self):
> print 'Goodbye world...'
> self.quit()
>
> if __name__ == '__main__':
> HelloButton(text='Hello subclass world').mainloop()
>
> ===================================================================
>
> I'm reading Programming Python 2nd edition published by O'reilly and
> also struggle to understand concept of class.
>
> 1. In the above example, variable named 'config' is used in 3 places.
> Are they all same or different?
>
> 2. I guess they're not all same.
> def __init__(self, parent=None, **config):
> Button.__init__(self, parent, config)
>
> I guess variable config in above 2 lines are same one.
> If then, why '**config' is used in __init__ method ?
> And I tried to use just 'config' instead of '**config', but that caused
> a error.
>
>
> Thanks in advance.
> ThomasLee (KJ Lee)
>
>
>
>
>
>
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice:
603-443-6155
fax:
801-459-9582