Re: Filtering out non-readable characters

2005-07-29 Thread Adriaan Renting
def StripNoPrint(self, S): from string import printable return .join([ ch for ch in S if ch in printable ]) Adriaan Renting| Email: [EMAIL PROTECTED] ASTRON | Phone: +31 521 595 217 P.O. Box 2 | GSM: +31 6 24 25 17 28 NL-7990 AA Dwingeloo |

Re: Filtering out non-readable characters

2005-07-29 Thread Steve Holden
Adriaan Renting wrote: def StripNoPrint(self, S): from string import printable return .join([ ch for ch in S if ch in printable ]) Adriaan Renting| Email: [EMAIL PROTECTED] ASTRON | Phone: +31 521 595 217 P.O. Box 2 | GSM: +31 6 24 25

Re: Filtering out non-readable characters

2005-07-29 Thread Steven Bethard
Steve Holden wrote: tt = .join([chr(i) for i in range(256)]) Or: tt = string.maketrans('', '') STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: Filtering out non-readable characters

2005-07-23 Thread Bengt Richter
On 17 Jul 2005 18:32:28 -0700, Raymond Hettinger [EMAIL PROTECTED] wrote: [George Sakkis] It's only obvious in the sense that _after_ you see this idiom, you can go back to the docs and realize it's not doing something special; OTOH if you haven't seen it, it's not at all the obvious

Re: Filtering out non-readable characters

2005-07-23 Thread Bengt Richter
On Sat, 16 Jul 2005 23:28:02 -0400, George Sakkis [EMAIL PROTECTED] wrote: Peter Hansen [EMAIL PROTECTED] wrote: George Sakkis wrote: Peter Hansen [EMAIL PROTECTED] wrote: Where did you learn that, George? Actually I first read about this in the Cookbook; there are two or three

Re: Filtering out non-readable characters

2005-07-23 Thread Bengt Richter
On Sun, 17 Jul 2005 15:42:08 -0600, Steven Bethard [EMAIL PROTECTED] wrote: Bengt Richter wrote: Thanks for the nudge. Actually, I know about generator expressions, but at some point I must have misinterpreted some bug in my code to mean that join in particular didn't like generator expression

Re: Filtering out non-readable characters

2005-07-19 Thread Ross
On 15 Jul 2005 17:33:39 -0700, MKoool [EMAIL PROTECTED] wrote: I have a file with binary and ascii characters in it. I massage the data and convert it to a more readable format, however it still comes up with some binary characters mixed in. I'd like to write something to just replace all

Re: Filtering out non-readable characters

2005-07-19 Thread Steven D'Aprano
On Tue, 19 Jul 2005 20:28:31 +1200, Ross wrote: On 15 Jul 2005 17:33:39 -0700, MKoool [EMAIL PROTECTED] wrote: I have a file with binary and ascii characters in it. I massage the data and convert it to a more readable format, however it still comes up with some binary characters mixed in.

Re: Filtering out non-readable characters

2005-07-18 Thread Michael Ströder
Peter Hansen wrote: ''.join(chr(c) for c in range(65, 91)) 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' Wouldn't this be a candidate for making the Python language stricter? Do you remember old Python versions treating l.append(n1,n2) the same way like l.append((n1,n2)). I'm glad this is forbidden now. Ciao,

Re: Filtering out non-readable characters

2005-07-18 Thread Peter Hansen
Michael Ströder wrote: Peter Hansen wrote: ''.join(chr(c) for c in range(65, 91)) 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' Wouldn't this be a candidate for making the Python language stricter? Why would that be true? I believe str.join() takes any iterable, and a generator (as returned by a

Re: Filtering out non-readable characters

2005-07-18 Thread Robert Kern
Michael Ströder wrote: Peter Hansen wrote: ''.join(chr(c) for c in range(65, 91)) 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' Wouldn't this be a candidate for making the Python language stricter? Do you remember old Python versions treating l.append(n1,n2) the same way like l.append((n1,n2)). I'm glad

Re: Filtering out non-readable characters

2005-07-17 Thread Peter Hansen
Steven D'Aprano wrote: On Sat, 16 Jul 2005 16:42:58 -0400, Peter Hansen wrote: Come on, Steven. Don't tell us you didn't have access to a Python interpreter to check before you posted: Er, as I wrote in my post: Steven who is still using Python 2.3, and probably will be for quite some

Re: Filtering out non-readable characters

2005-07-17 Thread Steven Bethard
Bengt Richter wrote: Thanks for the nudge. Actually, I know about generator expressions, but at some point I must have misinterpreted some bug in my code to mean that join in particular didn't like generator expression arguments, and wanted lists. I suspect this is bug 905389 [1]: def

Re: Filtering out non-readable characters

2005-07-17 Thread Raymond Hettinger
[George Sakkis] It's only obvious in the sense that _after_ you see this idiom, you can go back to the docs and realize it's not doing something special; OTOH if you haven't seen it, it's not at all the obvious solution to how do I get the first 256 characters. So IMO it should be

Re: Filtering out non-readable characters

2005-07-16 Thread Raymond Hettinger
Wow, that was the most thorough answer to a comp.lang.python question since the Martellibot got busy in the search business. -- http://mail.python.org/mailman/listinfo/python-list

Re: Filtering out non-readable characters

2005-07-16 Thread Peter Hansen
Bengt Richter wrote: identity = ''.join([chr(i) for i in xrange(256)]) unprintable = ''.join([c for c in identity if c not in string.printable]) And note that with Python 2.4, in each case the above square brackets are unnecessary (though harmless), because of the arrival of generator

Re: Filtering out non-readable characters

2005-07-16 Thread Steven D'Aprano
On Sat, 16 Jul 2005 10:25:29 -0400, Peter Hansen wrote: Bengt Richter wrote: identity = ''.join([chr(i) for i in xrange(256)]) unprintable = ''.join([c for c in identity if c not in string.printable]) And note that with Python 2.4, in each case the above square brackets are

Re: Filtering out non-readable characters

2005-07-16 Thread Peter Hansen
Steven D'Aprano wrote: On Sat, 16 Jul 2005 10:25:29 -0400, Peter Hansen wrote: Bengt Richter wrote: identity = ''.join([chr(i) for i in xrange(256)]) And note that with Python 2.4, in each case the above square brackets are unnecessary (though harmless), because of the arrival of generator

Re: Filtering out non-readable characters

2005-07-16 Thread Bengt Richter
On Sat, 16 Jul 2005 10:25:29 -0400, Peter Hansen [EMAIL PROTECTED] wrote: Bengt Richter wrote: identity = ''.join([chr(i) for i in xrange(256)]) unprintable = ''.join([c for c in identity if c not in string.printable]) And note that with Python 2.4, in each case the above square brackets

Re: Filtering out non-readable characters

2005-07-16 Thread George Sakkis
Bengt Richter [EMAIL PROTECTED] wrote: identity = ''.join([chr(i) for i in xrange(256)]) unprintable = ''.join([c for c in identity if c not in string.printable]) Or equivalently: identity = string.maketrans('','') unprintable = identity.translate(identity, string.printable) George

Re: Filtering out non-readable characters

2005-07-16 Thread Jp Calderone
On Sat, 16 Jul 2005 19:01:50 -0400, Peter Hansen [EMAIL PROTECTED] wrote: George Sakkis wrote: Bengt Richter [EMAIL PROTECTED] wrote: identity = ''.join([chr(i) for i in xrange(256)]) Or equivalently: identity = string.maketrans('','') Wow! That's handy, not to mention undocumented. (At

Re: Filtering out non-readable characters

2005-07-16 Thread Peter Hansen
Jp Calderone wrote: On Sat, 16 Jul 2005 19:01:50 -0400, Peter Hansen [EMAIL PROTECTED] wrote: George Sakkis wrote: identity = string.maketrans('','') Wow! That's handy, not to mention undocumented. (At least in the string module docs.) Where did you learn that, George?

Re: Filtering out non-readable characters

2005-07-16 Thread George Sakkis
Peter Hansen [EMAIL PROTECTED] wrote: Jp Calderone wrote: On Sat, 16 Jul 2005 19:01:50 -0400, Peter Hansen [EMAIL PROTECTED] wrote: George Sakkis wrote: identity = string.maketrans('','') Wow! That's handy, not to mention undocumented. (At least in the string module docs.) Where

Re: Filtering out non-readable characters

2005-07-16 Thread Peter Hansen
George Sakkis wrote: Peter Hansen [EMAIL PROTECTED] wrote: Where did you learn that, George? Actually I first read about this in the Cookbook; there are two or three recipes related to string.translate. As for string.maketrans, it doesn't do anything special for empty string arguments:

Re: Filtering out non-readable characters

2005-07-16 Thread George Sakkis
Peter Hansen [EMAIL PROTECTED] wrote: George Sakkis wrote: Peter Hansen [EMAIL PROTECTED] wrote: Where did you learn that, George? Actually I first read about this in the Cookbook; there are two or three recipes related to string.translate. As for string.maketrans, it doesn't do

Re: Filtering out non-readable characters

2005-07-16 Thread Steven D'Aprano
On Sat, 16 Jul 2005 16:42:58 -0400, Peter Hansen wrote: Steven D'Aprano wrote: On Sat, 16 Jul 2005 10:25:29 -0400, Peter Hansen wrote: Bengt Richter wrote: identity = ''.join([chr(i) for i in xrange(256)]) And note that with Python 2.4, in each case the above square brackets are