[Tutor] Re: getting input from keyboard

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Sun Dec 29 02:32:02 2002


On Sat, 28 Dec 2002, Poor Yorick wrote:

> Danny Yoo wrote:
>
> >
> >Hello!
> >
> >I've written a small Cookbook recipe to make using getch() somewhat
> >simpler:
> >
> >    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892
> >
>
>  Danny, it looks like your recipe has a typo.  self.impl will always end
> up being _GetchUnix().
>
>     def __init__(self):
>         try:
>             self.impl = _GetchWindows()
>         except ImportError: pass
>         self.impl = _GetchUnix()

Hi Poor Yorick,


Yikes!  You're right; the code is totally doing the wrong thing.  Thanks
for catching me on that one.


This should be one way to correct it:

###
     def __init__(self):
         try:
             self.impl = _GetchWindows()
         except ImportError: pass
         else:
             self.impl = _GetchUnix()
###


If that looks good with you, let's put a comment on that recipe with the
correction.


Thanks again!