Realny priklad: class MyGrep1: """ obsahuje metody na vyhladavanie retazcov v suboroch """ ...
def usage(self): """ Benutzungshilfe druecken """ usage =\ '\n %s Ver. %s, [rm] %s ([EMAIL PROTECTED])\n'\ % (self.short_progname,self.version,self.creationdate) \ + ' Searching for a list of strings in a list of a files\n\n'\ + ' [python] %s options \n\n'\ % self.progname \ + ' MANDATORY OPTIONS: \n'\ + ' -f <file> | --file <file>\n'\ + ' required argument:\n'\ + ' <file> - file name or list of file names delimited by " ",\n'\ + ' which can contain wildcard characters * and ?\n'\ + ' -s <string> | --string <string>\n'\ + ' required argument:\n'\ + ' <string> - string or list of strings delimited by " "\n'\ + ' OPTIONS:\n'\ + ' -h | --help print this help message\n'\ + ' -d | --dbginfo print some debug informations' print usage ... Metoda usage je vlastne command-line helpovnik ked zadas mygrep -h, alebo mygrep --help Teraz rozsirim funkcionalitu povodneho programu o nejaky novy command line option (-c resp --nocase) a preto musim zmenit aj helpovnik, takze vytvorim novy Class class MyGrep2(MyGrep1): """ rozsirenie triedy MyGrep1 o cmdline-option -c --nocase """ ... def usage(self): """ Benutzungshilfe druecken """ # Urspruengliche Parrent-Methode anrufen MyGrep1.usage(self) # Help-Erweiterung usage =\ ' -c | --nocase ignore case' print usage Takze rozsiril som help tak ze vytlacim stary help + este jeden riadok Roman Miklos <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] 10.11.2006 15:38 Please respond to Konference PyCZ <python@py.cz> To Konference PyCZ <python@py.cz> cc Subject Re: [python] class a subclass 1)Mozes premenovat prn v triede dietata, t.j. v b napr. na prnb, to znamena neprekryvat prn() v a: class a: def prn(self): print 'a',self def ma(self): self.prn() class b(a): def prnb(self): print 'b',self def ma(self): '''prekryje a.ma()''' a.ma(self) x=b() x.ma() 2) Alebo ak potrebujes v prn() objektu b nieco z prn() objektu a mozes ju najprv zavolat a potom tam este nieco dodat: class a: def prn(self): print 'a',self def ma(self): self.prn() class b(a): def prn(self): a.prn(self) print 'b',self def ma(self): '''prekryje a.ma()''' a.ma(self) x=b() x.ma() mtip <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] 10.11.2006 14:57 Please respond to Konference PyCZ <python@py.cz> To python@py.cz cc Subject [python] class a subclass Zdravim vsechny, mam nasledujici problem: potrebuji prekryt dve metody rodicovske tridy ve tride potomka, kde metoda v rodici vola prekryvanou metodu rodice. Jenze ta potom vola metodu potomka. Lze toto chovani nejak ovlivnit bez zasahu do rodice ? Zde je priklad: class a: def prn(self): print 'a',self def ma(self): self.prn() class b(a): def prn(self): print 'b',self def ma(self): '''prekryje a.ma()''' a.ma(self) x=b() x.ma() vysledkem je print z metody b.prn, a ja bych potreboval aby byl a.prn Diky za pomoc. Mirek. _______________________________________________ Python mailing list Python@py.cz http://www.py.cz/mailman/listinfo/python Mgr. Ing. Roman MIKLÓŠ Prvá stavebná sporiteľňa a.s. Bajkalská 30, P. O. Box 48 829 48 Bratislava 25 Tel.: +421/ 2 / 582 31 174 Fax: +421/ 2 / 582 31 109 _______________________________________________ Python mailing list Python@py.cz http://www.py.cz/mailman/listinfo/python Mgr. Ing. Roman MIKLÓŠ Prvá stavebná sporiteľňa a.s. Bajkalská 30, P. O. Box 48 829 48 Bratislava 25 Tel.: +421/ 2 / 582 31 174 Fax: +421/ 2 / 582 31 109 _______________________________________________ Python mailing list Python@py.cz http://www.py.cz/mailman/listinfo/python