Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'ok.': 0.04; 'subject:Python': 0.05; 'python': 0.08; 'from:addr:python': 0.09; 'method:': 0.09; 'word)': 0.09; 'python?': 0.15; '(sorry': 0.16; 'clear.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'reply-to:addr:python-list': 0.16; 'wrote:': 0.18; 'perl': 0.18; 'convert': 0.19; 'header:In-Reply- To:1': 0.22; 'table.': 0.23; 'string': 0.24; 'translation': 0.25; 'import': 0.27; 'bit': 0.28; 'print': 0.29; 'example': 0.29; 'header:User-Agent:1': 0.33; 'there': 0.33; 'to:addr:python-list': 0.34; 'received:84': 0.34; 'reply-to:addr:python.org': 0.34; 'subject:/': 0.35; 'device': 0.36; 'subject:with': 0.36; 'skip:" 10': 0.37; 'but': 0.37; 'think': 0.37; 'could': 0.37; 'doing': 0.38; 'subject: (': 0.40; 'to:addr:python.org': 0.40; 'quick': 0.61; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'naughty': 0.84; 'subject:Serial': 0.91 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=TvRkdUrh c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=9jsOeB20M3cA:10 a=Wj3GC6AdMgQA:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=5W085DuPLWPVZbKwyVIA:9 a=t10tH1v5dJDmjPaxSXsA:7 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Mon, 21 Nov 2011 18:20:01 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. References: <27511132.925.1321884055247.JavaMail.geo-discussion-forums@yqnf38> <2723247.1219.1321892899941.JavaMail.geo-discussion-forums@yqzz20> <22753805.1034.1321894337412.JavaMail.geo-discussion-forums@yqdr22> In-Reply-To: <22753805.1034.1321894337412.JavaMail.geo-discussion-forums@yqdr22> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321899609 news.xs4all.nl 6972 [2001:888:2000:d::a6]:56141 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16039 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)