[Tutor] reiterative programming

Neil Schemenauer nas-pytut at python.ca
Mon Oct 27 13:05:57 EST 2003


On Mon, Oct 27, 2003 at 10:34:27AM -0500, Stanfield, Vicki wrote:
> I want to loop through doing this until the returned value is a
> hex 4. I am using this:
> 
> 	while returnedval != '\0x4':
>                 output=port.read()
>                 returnedval= hex(ord(output))


You want '0x4', not '\0x4'.  The former is a string consisting of
the characters '0', 'x', and '4'.  The later is a string of the
characters NUL, 'x', '4'.  Personally, I would write the loop like
this:

    while 1:
        c = port.read(1)
        if c == '\x04':
            break

(although I'm guessing at what you are trying to do).

  Neil



More information about the Tutor mailing list