[Tutor] Line in a file

alan.gauld@bt.com alan.gauld@bt.com
Fri, 19 Jul 2002 13:50:04 +0100


>  >>> def printLine(fh, num):				# let's 
> ...   c = 0
> ...   for line in fh.xreadlines():
> ...     c = c + 1
> ...     if (line == num):
> ...       fh.seek(0)					# 
> ...       return line					# 

Only returns if line == num but line is a 
string not a num... should check if c==num...

Incidentally there's a potential bug in that you 
return None if the required line is never reached. 
Might be better to raise an exception instead?

Alan G.