I am using something similar to the question here:
Python: Undo a Python file readline() operation so file pointer is back in original state
but seems to be misbehaving.
My code: (values at runtime shown as comments)
def parse_shell(self, filename):
output = None
with open(self.shells_path + filename) as fp:
first_line = fp.readline()
# first_line = 'Last login: Tue Jun 9 07:13:26 on ttys0'
while len(string.split(first_line, '$')) == 1:
last_pos = fp.tell()
# last_pos = 43
first_line = fp.readline()
# first_line =' 2015-06-09 08:18:23 [coryj@Corys-MacBook-Pro ~]$ ping 10.2.2.1'
fp.seek(last_pos)
for line in fp.readline():
# line = ''
line_chunks = string.split(line, '$')
according to the docs, readline() should only return an empty string if it hits EOF. This particular file is over 200k so I don't see why I would get an empty string.