On Mon, Jun 13, 2011 at 3:18 AM, Ethan Furman <et...@stoneleaf.us> wrote:
>
> This is not beautiful code.

Agreed, but:

EOH, CHAR, DATE, FLOAT, INT, LOGICAL, MEMO, NUMBER = b'\rCDFILMN'

is a shorter way to write the same thing.

Going two per line makes it easier to mentally map the characters:

EOH, CHAR = b'\rC'
DATE, FLOAT = b'DF'
INT, LOGICAL = b'IL'
MEMO, NUMBER = b'MN'

Or, as a variant on Martin's solution:

FORMAT_CHARS = dict(
  EOH = '\r',
  CHAR= 'C',
  DATE = 'D',
  FLOAT = 'F',
  INT = 'I',
  LOGICAL = 'L',
  MEMO = 'M',
  NUMBER = 'N'
)

FORMAT_CODES = {name : char.encode('ascii') for name, char in FORMAT_CHARS}
globals().update(FORMAT_CODES)

Sure, there's no "one obvious way" at this stage, but that's because
we don't know yet if there even *should* be an obvious way to do this
(as conflating text and binary data is a bad idea in principle). By
not blessing any one way of handling the situation, we give
alternative solutions time to evolve naturally. If one turns out to be
clearly superior to the decode/process/encode cycle then hopefully
that will become clear at some point in the future.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to