Python IO performance?

Andrew Dalke adalke at
Fri Jun 6 01:58:19 CEST 2003

Mike Romberg:
>  I'm not so certain that these are equivalent.  I'm not really a perl
> expert, but I bet the perl version behaves more like the traditional
> cat in that it just sends the data from one source to the sink.

They are equivalent.  The fileinput module was written to mimic
Perl's behaviour for doing 'while (<>)'

> But
> the python fileinput module is reading the data a *line* at a time.
> This means that it has to examine each character to find the newlines.

So is Perl's.

>   I whiped up this example which is probably not equivalent either
> (benchmarks being what they are):

Perl's also tracks the line number, and will iterate through several
files if given in @ARGV (resetting the line numbers appropriately).
fileinput does this as well.

                    dalke at

More information about the Python-list mailing list