I just upgraded to Python 2.7.12 and my code is now erroring with rather unhelpful Mixing iteration and read methods would lose data errors. Googling for this yields a number of StackOverflow posts where people are iterating over a file, and then within the loop, doing calls on the file. This sounds like a good error for their case, but in my case the fixes are somewhat more inane.
This errors:
This errors:
persistence.write_dict_uint32_to_list_of_uint32s(output_file, { k: [] for k in read_set_of_uint32s(input_file) })This fixes that error:
set_value = persistence.read_set_of_uint32s(input_file)Another error at another location:
persistence.write_dict_uint32_to_list_of_uint32s(output_file, { k: [] for k in set_value })
persistence.write_set_of_uint32s(output_file, persistence.read_set_of_uint32s(input_file))Some simple rearranging makes this error go away:
set_value = persistence.read_set_of_uint32s(input_file)And finally, the next error at another location:
persistence.write_set_of_uint32s(output_file, set_value)
def read_string(f):And the fix for this:
s = ""
while 1:
v = f.read(1) # errors here
if v == '\0':
break
s += v
return s
def read_bytes(f, num_bytes):This error seems like a horribly broken idea, that is popping up in places it wasn't intended.
return f.read(num_bytes)
def read_string(f):
s = ""
while 1:
v = read_bytes(f, 1)
if v == '\0':
break
s += v
return s