[Tutor] Reading large bz2 Files

Stefan Behnel stefan_ml at behnel.de
Fri Feb 19 17:15:15 CET 2010


Norman Rieß, 19.02.2010 13:42:
> i am trying to read a large bz2 file with this code:
> 
> source_file = bz2.BZ2File(file, "r")
> for line in source_file:
>     print line.strip()
> 
> But after 4311 lines, it stoppes without a errormessage.

What does "stops" mean here? Does it crash? Does it exit from the loop? Is
the above code exactly what you used for testing? Are you passing a
filename? What platform is this on?


> The bz2 file is much bigger though.

How many lines does it have? How did you count them? Did you make sure that
you are reading from the right file?


> How can i read the whole file line by line?

Just as you do above, and it works for me. So the problem is likely elsewhere.

Stefan



More information about the Tutor mailing list