Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93948
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2015-07-16 11:30 -0700 |
| References | <rBHbx.75089$MO7.40532@fx10.iad> <Tbtfx.178924$Jv.102633@fx26.iad> <mm08nk$caf$1@dont-email.me> <3fec5a1e-44e6-4e3c-ab01-2703f2911c50@googlegroups.com> <mailman.559.1437026959.3674.python-list@python.org> |
| Message-ID | <6d0248bd-415d-4801-bfde-acab06317da7@googlegroups.com> (permalink) |
| Subject | Re: Keypress Input |
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
On Thursday, July 16, 2015 at 1:09:32 AM UTC-5, Terry Reedy wrote:
> This really is a nice example. Your rationale for defining an app class
> is the best I remember seeing.
Well thank you Terry. Your many years of selfless altruistic
offerings to this fine group are both inspiring and
educational. And i can happily admit that you are no doubt
much more of an asset to this group than i.
> > def evtKeyDown(self, event):
> > key = event.keysym.lower()
> > alert = False
Oops. I just noticed that i forgot to remove the "alert =
False" line. It was an artifact from one of my earlier
versions. It's obviously superfluous to we pyhtonistas, but
it could become a source of confusion to the shadow lurkers.
> > if key == 'r':
> > self.config(bg='red')
> > elif key == 'g':
> > self.config(bg='green')
> > elif key == 'b':
> > self.config(bg='blue')
> > else:
>
> Can condense block above to this easily extended code: (Replacing if
> if/elif/elif/... chains, when possible, is part of mastering Python.)
>
> try:
> self['bg'] = {'r':'red', 'g':'green', 'b':'blue'}[key]
> except KeyError:
Yes you make a good point. And i'm glad you injected this
alternative, as it offers yet another fine "teaching moment"
for the OP and this group.
[Warning: Caveat ahead!]
However, i must take exception with your claim that
replacing "classical conditional chains" with Python's
unofficial "pseudo case/switch" is key to: "mastering
Python". I feel there are instances when a "classical
condition chain" are more appropriate, and then other times,
when the "pseudo switch/case" is superior.
For me, I believe the "key to mastering Python" is not to
choose one method over the other (as some sort of religious
rule carved into stone), rather, to know when one method is more
appropriate than the other. That's my person opinion anyway.
> Adding parens to print, when there is a single object
> being printed, has no effect in 2.x and makes the
> statement work in 3.x. The following works the same in
> both.
>
> print("Mainloop has returned")
Yes, another fine teaching moment! But just to be clear of
my intentions: I only write code in full 2.x compliance, or
full 3.x compliance. And i do this because i don't want to
inject any "implicit version confusion" into my source code.
In fact, the only time i will mix the incompatible syntaxes
is when i can wrap them explicitly in an exception handler.
But since there is no exception to catch in this case, even
that option would be unavailable to me.
But again. The act of you pointing out this easily
overlooked difference between print 2.x and print(3.x) is
yet another opportunity at exploiting fundamental teaching
moments as they pop up. Hey, who would ever have "thunk" that
teaching could be as exciting and egotistically
fulfilling as a game of wack-a-mole! O:-)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-03 18:22 +0000
Re: Keypress Input Laura Creighton <lac@openend.se> - 2015-06-03 20:59 +0200
Re: Keypress Input Gary Herron <gherron@digipen.edu> - 2015-06-03 12:15 -0700
Re: Keypress Input Gary Herron <gherron@digipen.edu> - 2015-06-03 11:47 -0700
Re: Keypress Input Laura Creighton <lac@openend.se> - 2015-06-04 12:50 +0200
Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-06 18:28 +0000
Re: Keypress Input Laura Creighton <lac@openend.se> - 2015-06-06 22:52 +0200
Re: Keypress Input Chris Angelico <rosuav@gmail.com> - 2015-06-07 07:20 +1000
Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-06-06 22:31 -0600
Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-15 05:15 +0000
Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-16 15:09 +0000
Re: Keypress Input Christian Gollwitzer <auriocus@gmx.de> - 2015-06-19 07:20 +0200
Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-20 14:59 +0000
Re: Keypress Input Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-15 18:03 -0700
Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-07-15 22:30 -0600
Re: Keypress Input Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-16 10:22 -0700
Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-07-16 15:27 -0600
Re: Keypress Input Terry Reedy <tjreedy@udel.edu> - 2015-07-16 02:08 -0400
Re: Keypress Input Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-16 11:30 -0700
Re: Keypress Input Terry Reedy <tjreedy@udel.edu> - 2015-07-16 03:10 -0400
Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-07-16 15:29 -0600
Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-15 05:23 +0000
Re: Keypress Input Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-06-15 12:22 +0100
Re: Keypress Input Grant Edwards <invalid@invalid.invalid> - 2015-06-15 15:22 +0000
Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-06-16 11:15 -0600
Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-16 20:06 +0000
Re: Keypress Input Grant Edwards <invalid@invalid.invalid> - 2015-06-16 20:49 +0000
Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-06-16 19:22 -0600
Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-06-18 16:42 -0600
Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-06-20 15:02 +0000
Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-06-20 10:30 -0600
Re: Keypress Input Paul Rubin <no.email@nospam.invalid> - 2015-06-16 14:22 -0700
Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-07-15 19:05 +0000
Re: Keypress Input Michael Torrie <torriem@gmail.com> - 2015-07-15 13:17 -0600
Re: Keypress Input John McKenzie <davros@bellaliant.net> - 2015-08-16 19:45 +0000
csiph-web