Set parity of a string

Peter Hansen peter at engcorp.com
Sun Jan 23 19:12:00 EST 2005


snacktime wrote:
> Is there a module that sets the parity of a string?  I have an
> application that needs to communicate with a host using even parity 
> So what I need is before sending the message, convert it from space to
> even parity.  And when I get the response I need to convert that from
> even to space parity.

By what means are the messages being delivered?  I've rarely
seen parity used outside of simple RS-232-style serial communications.
Certainly not (in my experience, though it's doubtless been done)
in TCP/IP based stuff.  And if it's serial, parity can be
supplied at a lower level than your code.

As to the specific question: a module is not really required.
The parity value of a character depends only on the binary
value of that one byte, so a simple 128-byte substitution
table is all you need, plus a call to string.translate for
each string.

-Peter



More information about the Python-list mailing list