Stripping whitespace

R

ryan k

And your reasons for coming to that stridently expressed conclusion
after reading a posting that was *not* addressed to you are .....?

Because his tone is extremely condescending and quite frankly
annoying. From this post to others, his terse remarks scar this
community and fade its atmosphere of friendliness.
 
C

cokofreedom

Because his tone is extremely condescending and quite frankly
annoying. From this post to others, his terse remarks scar this
community and fade its atmosphere of friendliness.

And your response was any better because...?
 
R

Reedick, Andrew

-----Original Message-----
From: [email protected] [mailto:python-
[email protected]] On Behalf Of John Machin
Sent: Wednesday, January 23, 2008 5:48 PM
To: (e-mail address removed)
Subject: Re: Stripping whitespace

Why is it that so many Python people are regex adverse? Use the dashed
line as a regex. Convert the dashes to dots. Wrap the dots in
parentheses. Convert the whitespace chars to '\s'. Presto! Simpler,
cleaner code.
pattern = re.sub(r'-', r'.', line)
pattern = re.sub(r'\s', r'\\s', pattern)
pattern = re.sub(r'([.]+)', r'(\1)', pattern)

Consider this:
pattern = ' '.join('(.{%d})' % len(x) for x in line.split())

Good. But the main drawback to using split+join is that it works if
there is only one whitespace char acting as a column separator
(split+join will compress multiple whitespace characters down to one
char.) Normally, it's safe to assume a one character separator between
columns, however since the input is supposed to be tab delimited (but
wasn't) and tabs tend to get randomly converted to spaces depending on
which butterfly is flapping its wings at any given instant, keeping the
original whitespace column separators is probably a good idea.



*****

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA622
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top