I found this class to take a space delimited file and if there are multiple spaces, they will be treated as a single separator. How do I see the effects of this on a file?
class FH:
def __init__(self, fh):
self.fh = fh
def close(self):
self.fh.close()
def seek(self, arg):
self.fh.seek(arg)
def fix(self, s):
return ' '.join(s.split())
def next(self):
return self.fix(self.fh.next())
def __iter__(self):
for line in self.fh:
yield self.fix(line)
so how do I see this work on a file? I've created a file with multiple spaces to see it in action.
I've done this:
In [31]: FH('classfhtry.csv') Out[31]: In [32]: r = FH('classfhtry.csv') In [33]: r Out[33]: In [34]: print r -------> print(r) In [35]: f = open(r) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /home/blahblahblah/Documents/Programming/EXERCISES/piece.py in () ----> 1 2 3 4 5 TypeError: coercing to Unicode: need string or buffer, instance found
I want to see my class in action! Thanks for any 2cents!