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


Groups > comp.lang.python > #16039

Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

Date 2011-11-21 18:20 +0000
From MRAB <python@mrabarnett.plus.com>
Subject Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.
References <27511132.925.1321884055247.JavaMail.geo-discussion-forums@yqnf38> <mailman.2900.1321885611.27778.python-list@python.org> <2723247.1219.1321892899941.JavaMail.geo-discussion-forums@yqzz20> <mailman.2912.1321894079.27778.python-list@python.org> <22753805.1034.1321894337412.JavaMail.geo-discussion-forums@yqdr22>
Newsgroups comp.lang.python
Message-ID <mailman.2924.1321899609.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 21/11/2011 16:52, Matthew Lenz wrote:
> Ahh. Ok.  So how would I go about doing that with python?  I think in
> perl (sorry for the naughty word) I could use the tr// (translate)
> but is there a quick way to do so with python?  Is it going to be
> necessary to convert commands I SEND to the device or only convert
> what I receive?

Python strings have a .translate method:

# Example in Python 2
import string

# From top bit set...
from_chars = "".join(chr(c | 0x80) for c in range(0x7F))

# ...to top bit clear.
to_chars = "".join(chr(c) for c in range(0x7F))

# Build the translation table.
force_clear = string.maketrans(from_chars, to_chars)

s = "\x41\xC1"
print s
print s.translate(force_clear)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Non-POSIX parity (mark/space) with Python-Serial on Linux. mlenz@nocturnal.org - 2011-11-21 06:00 -0800
  Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Matthew Lenz <matthew@nocturnal.org> - 2011-11-21 06:16 -0800
  Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Nizamov Shawkat <nizamov.shawkat@gmail.com> - 2011-11-21 15:26 +0100
    Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Matthew Lenz <matthew@nocturnal.org> - 2011-11-21 08:28 -0800
      Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Chris Angelico <rosuav@gmail.com> - 2011-11-22 03:41 +1100
      Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. David Riley <fraveydank@gmail.com> - 2011-11-21 11:47 -0500
        Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Matthew Lenz <matthew@nocturnal.org> - 2011-11-21 08:52 -0800
        Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Matthew Lenz <matthew@nocturnal.org> - 2011-11-21 08:52 -0800
          Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. David Riley <fraveydank@gmail.com> - 2011-11-21 12:22 -0500
            Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Matthew Lenz <matthew@nocturnal.org> - 2011-11-21 09:59 -0800
            Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Matthew Lenz <matthew@nocturnal.org> - 2011-11-21 09:59 -0800
              Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. David Riley <fraveydank@gmail.com> - 2011-11-21 13:12 -0500
          Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. MRAB <python@mrabarnett.plus.com> - 2011-11-21 18:20 +0000
      Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. gene heskett <gheskett@wdtv.com> - 2011-11-21 12:25 -0500
      Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. David Riley <fraveydank@gmail.com> - 2011-11-21 12:50 -0500
    Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Matthew Lenz <matthew@nocturnal.org> - 2011-11-21 08:28 -0800
  Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. gene heskett <gheskett@wdtv.com> - 2011-11-21 13:33 -0500
    Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Matthew Lenz <matthew@nocturnal.org> - 2011-11-21 11:29 -0800
      Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Grant Edwards <invalid@invalid.invalid> - 2011-11-21 19:42 +0000
    Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Matthew Lenz <matthew@nocturnal.org> - 2011-11-21 11:29 -0800
      Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. David Riley <fraveydank@gmail.com> - 2011-11-21 15:42 -0500
        Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Grant Edwards <invalid@invalid.invalid> - 2011-11-21 23:08 +0000
          Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Grant Edwards <invalid@invalid.invalid> - 2011-11-21 23:09 +0000
            Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Chris Angelico <rosuav@gmail.com> - 2011-11-22 11:32 +1100

csiph-web