Re: [PyKDE] Can I use QString as key in Python dictionary?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Sebastian Kügler schrieb: > On Thursday 02 June 2005 04:10, Matej Cepl wrote: > >>I have this simple dialog in PyQt, but whenever I press any item in >>the list (or click OK), I get this error: >> >>chelcicky:pycatsel$ ./pycatsel >>Traceback (most recent call last): >> File >>"/home/matej/archiv/programky/vim-qadas/pycatsel/selectCode.py",\ >>line 148, in Quit >>note = unicode(self.dictCategories[key]) >>KeyError: <__main__.qt.QString object at 0xb7e12c5c> >>chelcicky:pycatsel$ >> >>Does anybody have any idea, what's wrong? Can I use QString as a key >>in Python dictionary (both key and dict's values are QStrings)? > > from qt import * QString("foo") is QString("foo") > > False > > As you can see these two QString are different objects, so there's > actually no such key. > > k = QString("bla") mydict = {QString("bla"):"foobar"} mydict[k] > > Traceback (most recent call last): > File "", line 1, in ? > KeyError: > > As you can see, it yields a KeyError because k is actually no key in > mydict. However, you can use a QString as a key, but you have to use > exactly that reference (not a *similar* one): > > k = QString("bla") mydict = {k:"foobar"} mydict[k] > > 'foobar' One could think about changing the QString implementation of __hash__ to use the strings's contents only. This shouldn't be too difficult (although I didn't try it out, so I'm probably wrong.). greetings Torsten - -- Torsten Marek <[EMAIL PROTECTED]> ID: A244C858 -- FP: 1902 0002 5DFC 856B F146 894C 7CC5 451E A244 C858 Keyserver: subkeys.pgp.net -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCnqJhfMVFHqJEyFgRApJrAJ4xX4Vf5ECpcfWxlqPbenwQFh8pOQCdGK4J b+8pDuGjT75m6I6gcjxDedM= =3gKN -END PGP SIGNATURE- ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] Can I use QString as key in Python dictionary?
On Thursday 02 June 2005 04:10, Matej Cepl wrote: > I have this simple dialog in PyQt, but whenever I press any item in > the list (or click OK), I get this error: > > chelcicky:pycatsel$ ./pycatsel > Traceback (most recent call last): > File > "/home/matej/archiv/programky/vim-qadas/pycatsel/selectCode.py",\ > line 148, in Quit > note = unicode(self.dictCategories[key]) > KeyError: <__main__.qt.QString object at 0xb7e12c5c> > chelcicky:pycatsel$ > > Does anybody have any idea, what's wrong? Can I use QString as a key > in Python dictionary (both key and dict's values are QStrings)? >>> from qt import * >>> QString("foo") is QString("foo") False As you can see these two QString are different objects, so there's actually no such key. >>> k = QString("bla") >>> mydict = {QString("bla"):"foobar"} >>> mydict[k] Traceback (most recent call last): File "", line 1, in ? KeyError: As you can see, it yields a KeyError because k is actually no key in mydict. However, you can use a QString as a key, but you have to use exactly that reference (not a *similar* one): >>> k = QString("bla") >>> mydict = {k:"foobar"} >>> mydict[k] 'foobar' Cheers, sebas -- http://vizZzion.org | GPG Key ID: 9119 0EF9 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Political language [...] is designed to make lies sound truthful and murder respectable, and to give an appearance of solidity to pure wind. - George Orwell, 1984 pgpwf1eEa5TrJ.pgp Description: PGP signature ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[PyKDE] Can I use QString as key in Python dictionary?
Hi, I have this simple dialog in PyQt, but whenever I press any item in the list (or click OK), I get this error: chelcicky:pycatsel$ ./pycatsel Traceback (most recent call last): File "/home/matej/archiv/programky/vim-qadas/pycatsel/selectCode.py",\ line 148, in Quit note = unicode(self.dictCategories[key]) KeyError: <__main__.qt.QString object at 0xb7e12c5c> chelcicky:pycatsel$ Does anybody have any idea, what's wrong? Can I use QString as a key in Python dictionary (both key and dict's values are QStrings)? Thanks a lot, 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 I am a Roman Catholic, so that I do not expect `history' to be anything but a `long defeat' -- though it contains (and in a legend may contain more clearly and movingly) some samples or glimpses of final victory. -- J.R.R. Tolkien pycatsel.tar.bz2 Description: BZip2 compressed data ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] Re: [Eric] How to use ipython ?
Am Mittwoch, 1. Juni 2005 14:20 schrieb Diez B. Roggisch: > > Actually the IPython feature I'm the most missing, if not the only one, > > is completion. This is a valuable improvement over the standard python > > interpreter, when in the implementation/testing phase ; that's why it > > made sense to me to have IPython run "inside" a python IDE... > > My eric has tab-completion working in it's interpreter already - in form of > a window popping up giving me the possible choices. Which is nice, but > could IMHO enhanced a great deal by implementing in incrementally, like the > autocompletion in scintill. It has the scintilla autocompletion as well > Any chances we see that coming, Detlev? I'll look into this for the 3.8 development, but won't promise anything. > > Regards, > > Diez > > ___ > PyKDE mailing listPyKDE@mats.imk.fraunhofer.de > http://mats.imk.fraunhofer.de/mailman/listinfo/pykde Detlev -- Detlev Offenbach [EMAIL PROTECTED] ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
Re: [PyKDE] Re: [Eric] How to use ipython ?
> Actually the IPython feature I'm the most missing, if not the only one, is > completion. This is a valuable improvement over the standard python > interpreter, when in the implementation/testing phase ; that's why it made > sense to me to have IPython run "inside" a python IDE... My eric has tab-completion working in it's interpreter already - in form of a window popping up giving me the possible choices. Which is nice, but could IMHO enhanced a great deal by implementing in incrementally, like the autocompletion in scintill. Any chances we see that coming, Detlev? Regards, Diez ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[PyKDE] Re: [Eric] How to use ipython ?
On Tuesday 31 May 2005 18:59, Detlev Offenbach wrote: > Hi, > > I haven't tried this and actually I don't see the need for it. Actually the IPython feature I'm the most missing, if not the only one, is completion. This is a valuable improvement over the standard python interpreter, when in the implementation/testing phase ; that's why it made sense to me to have IPython run "inside" a python IDE... > IPython's > features will most probably not show up in the Python shell of the IDE. The > "Custom python interpreter" is meant to name a python interpreter to run > the debugger client side. I'm not sure I understood correctly : is the interpreter appearing at the bottom of Eric the one that runs the debugger client side ? Cheers, Nicolas ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde