On Apr 9, 5:05 pm, [EMAIL PROTECTED] wrote: > I'm not sure if I have even phrased that right but anyway.... > > How does one find (in the standard Python documentation) information > about things like the iteritems() method and the enumerate() function. > > They are mentioned in the tutorial as ways of getting more information > as you loop through an object but there seems to be no easy way to > find the definitive documentation of these sorts of methods and > functions. OK, if I know the name before I start I can probably find > what I want, but what if I want to know how to extract some > information from an object as I loop and don't know what I want is > called? > > My particular quest that raised this was a way to get the line number > as I iterate through the lines of a file:- > > f = open(fn, 'r') > lineNo = 0 > for ln in f: > lineNo += 1 > > Is there a neater way of getting that line number as I go? If so how > am I meant to find out about it?
There is a neater way, and you mention it in your question: f = open('myfile') for lineno, line in enumerate(f): # Do stuff How to find out about it? I suppose you need to get familiar with python iterators/iterables and the functions to manipulate them. How to do that depends on your prior experience with such concepts. Unfortunately I am not able to provide you with a good link :( -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list