[Tutor] Fastest way to iterate through a file

Kent Johnson kent37 at tds.net
Tue Jun 26 01:33:41 CEST 2007


Robert Hicks wrote:
> I have a script at work where I have a list of id numbers and I am doing a:
> 
> for line in ehFile:

That is fine

>      for id in line:

I don't know what this is for - line is a string, iterating it will give 
you every character is the line.
> 	
> I am then going through that file and finding the line the id is on and 
> printing the next line out. It takes a few seconds to see the output to 
> the screen (the Perl version whips by) which got me to thinking I could 
> be doing it faster (as I want to move it from Perl to Python).
> 
> If you need all the code I can post that tomorrow or I can try any ideas 
> posted to this.

A bit more code would help.

Kent


More information about the Tutor mailing list