[wxpython-users] Re: Use the 'in' statement, always!

Jorgen Bodde jorgen.maillist at gmail.com
Wed May 7 23:47:35 PDT 2008


Hi Chester,

Instead of spamming the mailinglist with tons of messages about the
same issue, it would be great if you simply add it to a bugtracker or
something. I have no doubt wxPython code still has inconsistencies or
could be written with cleaner code, but that's all part of the
process. If I read back code I wrote a year ago I sometimes look in
the mirror to see if I am still the same person.

Maybe there is a wxPyWiki page, or a bugtracker, but please put all
great ideas you have about improving the code in there, and not on
this mailinglist as it is for people who want to be helped developing
wxPython, hence the name wxpython-USERS at lists.wxwidgets.org

Thanks,
- Jorgen


On Thu, May 8, 2008 at 12:37 AM, Chester <wxpythoner at gmail.com> wrote:
> Just kill the has_key() method that is in your brain. It's dead...
>
> The 'in' statement is in any circumstance the most clean and elegant
> solution that the Python programming language has to offer in this context.
> The 'in' statement works everytime on any object of type tuple, list, or
> dictionary. I hope you understand now how important that is. Be clean! And
> be well. ;)
>
>
>
>
>
> On Thu, May 8, 2008 at 12:30 AM, Chester <wxpythoner at gmail.com> wrote:
> > The initial e-mail had a typo. Here is its fix...
> >
> >
> >
> > The has_key() method is limited as opposed to the 'in' statement! I have a
> proof.
> >
> >
> > TUPLE ('in' statement):  WORKS!
> > >>> fruit_basket = ("banana", "orange")
> > >>> "orange" in fruit_basket
> > True
> >
> >
> > TUPLE (has_key method):  NOT WORKING!
> > >>> fruit_basket = ("banana", "orange")
> >
> >
> >
> > >>> fruit_basket.has_key("orange")
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> > AttributeError: 'tuple' object has no attribute 'has_key'
> >
> >
> > LIST ('in' statement):  WORKS!
> > >>> fruit_basket = ["banana", "orange"]
> > >>> "orange" in fruit_basket
> > True
> >
> >
> > LIST (has_key method):  NOT WORKING!
> > >>> fruit_basket = ["banana", "orange"]
> > >>> fruit_basket.has_key("orange")
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> > AttributeError: 'list' object has no attribute 'has_key'
> >
> >
> > DICTIONARY ('in' statement):  WORKS!
> > >>> fruit_basket = {"banana": 123, "orange": 456}
> > >>> "orange" in fruit_basket
> > True
> >
> >
> > DICTIONARY (has_key method):  WORKS!
> > >>> fruit_basket = {"banana": 123, "orange": 456}
> > >>> fruit_basket.has_key("orange")
> > True
> >
> >
> > As you see, the 'in' statement gives more clean code and works on tuples,
> lists, and dictionaries. The poor old has_key() method works only on
> dictionary objects. No wonder Guido removed this stupid method out of Python
> in version 3.0. And you still prefer the has_key method?
>
>
> _______________________________________________
>  wxpython-users mailing list
>  wxpython-users at lists.wxwidgets.org
>  http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
>
>


More information about the wxpython-users mailing list