Marc 'BlackJack' Rintsch wrote: > On Sun, 29 Jul 2007 12:24:56 -0700, CC wrote: >>The next step consists of printing out the ASCII printable characters. >>I have devised the following silliness: >> >>printable = ' >>[EMAIL PROTECTED]&8*9(0)aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\ >>`~-_=+\\|[{]};:\'",<.>/?' > > 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. >>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? If so then perhaps the translation would be better. >>I'd like to display the non-printable characters differently, since they >>can't be distinguished from genuine period '.' characters. Thus, I may >>use ANSI escape sequences like: >> >>for c in ln: >> if c in printable: sys.stdout.write(c) >> else: >> sys.stdout.write('\x1B[31m.') >> sys.stdout.write('\x1B[0m') >> >>print > > `re.sub()` might be an option here. Yeah, that is an interesting option. Since I don't wish to modify the block of data unless the user specifically edits it, so I might prefer the simple display operation. > For escaping: > > In [90]: '\n'.encode('string-escape') > Out[90]: '\\n' Hmm, I see there's an encoder that can do my hex display too. Thanks for the input! -- _____________________ Christopher R. Carlen [EMAIL PROTECTED] SuSE 9.1 Linux 2.6.5 -- http://mail.python.org/mailman/listinfo/python-list