Scott David Daniels wrote:
Here's how I'd do it:
with open('deheap/deheap.py', 'rU') as source:
for line in source:
print line.rstrip() # Avoid trailing spaces as well.
This should handle \n, \r\n, and \n\r lines.
Unfortunately, a raw rstrip() eats other whitespace that may be
important. I frequently get tab-delimited files, using the
following pseudo-code:
def clean_line(line):
return line.rstrip('\r\n').split('\t')
f = file('customer_x.txt')
headers = clean_line(f.next())
for line in f:
field1, field2, field3 = clean_line(line)
do_stuff()
if field3 is empty in the source-file, using rstrip(None) as you
suggest triggers errors on the tuple assignment because it eats
the tab that defined it.
I suppose if I were really smart, I'd dig a little deeper in the
CSV module to sniff out the "right" way to parse tab-delimited files.
-tkc
--
http://mail.python.org/mailman/listinfo/python-list