is there a problem on this simple code

Tim Roberts timr at probo.com
Wed Mar 16 01:31:11 EST 2005


jrlen balane <nbbalane at gmail.com> wrote:

>why is it that here:
>
>1)rx_data = ser.read(10)
>    (rx_command, rx_msg_no, rx_no_databyte, temp1, temp2, pyra1,
>pyra2, voltage, current, rx_checksum) = unpack('10B', rx_data)
>    print rx_command, rx_msg_no, rx_no_databyte, temp1, temp2, pyra1,
>pyra2, voltage, current, rx_checksum
> 
>>>> type (rx_command)
><type 'int'>
>
>but here:
>
>2)rx_data_command = ser.read()
>    (rx_command) = unpack('1B', rx_data_command)
>
>>>> type (rx_command)
><type 'tuple'>
>
>how can i make rx_command of type 'int' if i am to use 2)?

Did you get an answer to this?  I couldn't see any responses.  The answer
is either:

    rx_command = unpack('1B', rx_data_command)[0]

or

    (rx_command,) = unpack('1B', rx_data_command) 
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list