[PyKDE] Re: Can I use QString as key in Python dictionary?

Matej Cepl cepl at surfbest.net
Thu Jun 2 14:47:38 BST 2005


Gerard Vermeulen wrote:
> A Python string is immutable and a QString is mutable.
> 
> You'll may get undefined behaviour if you change a QString key while
> manipulating a dictionary containing that QString key.

Thanks a lot, the end of mystery. So I will probably stay with my
subclassing dict:

class NoteDict(dict):
    def __init__(self):
        pass

    def __getitem__(self,y):
        key = unicode(y)
        return dict.__getitem__(self,key)

    def __setitem__(self,i,y):
        key = unicode(i)
        dict.__setitem__(self,key,y)

    def __delitem__(self,y):
        key = unicode(y)
        dict.__delitem__(self,key)

Is there any better way how to do it?

        Matej

-- 
Matej Cepl, http://www.ceplovi.cz/matej
GPG Finger: 89EF 4BC6 288A BF43 1BAB  25C3 E09F EF25 D964 84AC
138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488
 
If it dies, it's biology.  If it blows up, it's chemistry,
and if it doesn't work, it's physics.
        -- University bathroom graffito





More information about the PyQt mailing list