Hex editor display - can this be more pythonic?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Mon Jul 30 02:22:49 EDT 2007


On Sun, 29 Jul 2007 18:27:25 -0700, CC wrote:

> Marc 'BlackJack' Rintsch wrote:
>> I'd use `string.printable` and remove the "invisible" characters like '\n'
>> or '\t'.
> 
> What is `string.printable` ?  There is no printable method to strings, 
> though I had hoped there would be.  I don't yet know how to make one.

In [8]: import string

In [9]: string.printable
Out[9]: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'(
)*+,-./:;<=>?@[\\]^_`{|}~\t\n\r\x0b\x0c'

>>>for c in ln:
>>>     if c in printable: sys.stdout.write(c)
>>>     else: sys.stdout.write('.')
> 
>> The translation table can be created once and should be faster.
> 
> I suppose the way I'm doing it requires a search through `printable` for 
> each c, right?  Whereas the translation would just be a lookup 
> operation?

Correct.  And it is written in C.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list