metaclass ???
BruceKL WhoH
BruceWhoHKL at gawab.com
Wed Aug 18 23:02:23 EDT 2004
Mike C. Fletcher:
Now I know that we can use metaclass to add method for class,not instance.
Maybe I never need to use metaclass. Perhaps I'll understand it when I'm really need something like this.
Thanks for your help.
======= 2004-08-19 10:36:17 Mike C. Fletcher wrote: =======
>BruceKL WhoH wrote:
>...
>
>> What I'm trying to do is :
>> I want to make two class, they are just subtly different,for example
>>
>>
>...
>
>>all other codes are identical,just f is different.
>> So can I use meta-class here? Or I should do this by another way?
>>
>>
>If this is the entire specification of what you need to do, it really
>seems as though you'd be better off with mix-in classes. Your code would
>then look like this:
>
>class Base:
>"""Base class providing common functionality"""
># your shared code here
>
>class A( Base ):
>"""Overrides method f only"""
>def f(self):
>print 'a'
>
>class B( Base ):
>"""Overrides method f only"""
>def f(self):
>print 'b'
>
>The first page of the presentation is intended to warn you that, in
>general, most programmers never need to use metaclasses, even after
>years of work in the language. The use cases for them are fairly exotic,
>not the kind of thing you find in "normal" programming operations.
>
>There are cases where you might want to use metaclasses to inject a
>method into a class (as covered in the presentation), but those
>use-cases tend to be more involved than simply wanting to have 1 method
>change. Those cases are normally going to involve making a *decision* at
>run-time as to which method implementation to include, for instance
>based on the presence/absence of other methods or a data-attribute of
>the class.
>
>> BTW,your pdf is quite nice,how do you make it? Beamer,pdfscreen, or PPT ?
>>
>>
>OpenOffice.org Presenter (PowerPoint-like app) has a built-in export to PDF.
>
>Have fun,
>Mike
>
>________________________________________________
> Mike C. Fletcher
> Designer, VR Plumber, Coder
> http://www.vrplumber.com
> http://blog.vrplumber.com
>
>--
>http://mail.python.org/mailman/listinfo/python-list
>.
= = = = = = = = = = = = = = = = = = = =
BruceKL WhoH
BruceWhoHKL at gawab.com
2004-08-19
More information about the Python-list
mailing list