Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107698 > unrolled thread

Re: How to read from serial port?

Started byBen Finney <ben+python@benfinney.id.au>
First post2016-04-27 11:27 +1000
Last post2016-04-27 00:26 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How to read from serial port? Ben Finney <ben+python@benfinney.id.au> - 2016-04-27 11:27 +1000
    Re: How to read from serial port? wxjmfauth@gmail.com - 2016-04-27 00:26 -0700

#107698 — Re: How to read from serial port?

FromBen Finney <ben+python@benfinney.id.au>
Date2016-04-27 11:27 +1000
SubjectRe: How to read from serial port?
Message-ID<mailman.136.1461720464.32212.python-list@python.org>
Gonzalo V <gvm2121@gmail.com> writes:

> Try print('blaba'+str(out))

I doubt that gives the desired result for a bytes object. Did you try it?

    >>> foo = b'\xde\xad\xbe\xef'
    >>> str(foo)
    "b'\\xde\\xad\\xbe\\xef'"
    >>> print(str(foo))
    b'\xde\xad\xbe\xef'

Yes, the “b'” and backslashes are all part of the output.

> saludos,
> desde un móvil.

Please don't top-post. If that means you need to wait until you are at a
device with proper keyboard, then please do that.

-- 
 \           “I have one rule to live by: Don't make it worse.” —Hazel |
  `\                                                          Woodcock |
_o__)                                                                  |
Ben Finney

[toc] | [next] | [standalone]


#107712

Fromwxjmfauth@gmail.com
Date2016-04-27 00:26 -0700
Message-ID<825accee-b928-4856-b477-5c63493e0712@googlegroups.com>
In reply to#107698
And the correct answer is...

>>> out = b'\x00\x61\x80\xff'
>>> print('Receiving...', [b for b in out])
Receiving... [0, 97, 128, 255]
>>> # or
>>> print('Receiving...', ' '.join([hex(b) for b in out]))
Receiving... 0x0 0x61 0x80 0xff
>>> # or ...

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web