[Tutor] (getch() equivalent) [fun with imports]

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Sun Mar 9 14:30:02 2003


> ###
> try:
>     import msvcrt
> catch:
  ^^^^^
>     msvcrt = None
>                    ## By this time, I can assume msvcrt is defined,
>                    ## although it might be set to None...


Oh good grief, not again!


I had been programming in the Java language for the past two weeks, and
I've gotten my keywords confused again.  Give me a few minutes to context
switch... ok, there, that's better.

Java uses the keyword "catch" for an exception block definition, but
Python uses an alternative keyword "except".  The corrected Python code
should use "except":

###
try:
    import msvcrt
except:
    msvcrt = None
###

Again, my apologies for being so sloppy about this!