Of console I/O, characters, strings & dogs

David David
Tue Dec 30 01:53:45 CET 2008

I am trying getch() from msvcrt.  The following module
has been run with 3 different concatination statements
and none yield a satisfactory result.    Python 3.0

# script12
import msvcrt
shortstr1 = 'd' + 'o' + 'g'
char1 = msvcrt.getch()
char2 = msvcrt.getch()
char3 = msvcrt.getch()
         <  alternatives for line 8 below  >

               print(shortstr1) gives    dog    of course.
               If the same char are entered individually at the
               console,  as char1, 2 & 3, using msvcrt.getch(),
               I have not been able to get out a plain dog.

       If line 8 is   shortstr2 = char1[0] + char2[0] + char3[0]
            print(shortstr2)  yields     314

       If line 8 is   shortstr2 = 'char1[0]' + 'char2[0]' + 'char3[0]'
            print(shortstr2)  yields     char1[0]char2[0]char3[0]

       If line 8 is   shortstr2 = char1 + char2 + char3
            print(shortstr2)  yields    b 'dog'
                    Is the latter out of "How to Speak Redneck"  ?

              Possibly b means bit string.  But how do I get a plain 
              dog out of these char console entries ?   
              The 3.0 tutorial doesn't discuss console I/O.
                                 Found msvcrt in Python in a Nutshell.

                       An old c programmer learns that this b 'Python'

More information about the Python-list mailing list