[PyKDE] Spiffy stuff...

dan dan at eevolved.com
Sun Dec 24 13:44:39 GMT 2000


I read stuff about subclassing and references and I thought maybe this stuff 
could help someone else...

I could explain, or you could look at the code :)

----------------------
from qt import *

class PatchedQString(QString):
    def output(self):       # new method that you want to add in qstring
        print eval(`self`)

    def utf8(self):         # method you want to 'patch'
        print "requested utf8"
        return QString.utf8()

QString = PatchedQString    # patch existing class

newvar = QString(u"Here is some initializer string")
newvar.output()         # call new method
print newvar.utf8()     # prints out "requested utf8() AND
                              # returns the classic QString.utf8()

-----------------------

I'm sure you could think of a use for this :-)

Dan




More information about the PyQt mailing list