Re: Help please!
Prasad, Ramit <ramit.prasad <at> jpmorgan.com>
2012-07-30 20:18:00 GMT
> Hello all! I have a very simple question but I'm very new to python. Could you
> describe to me what the following piece of Python code says in English
Welcome to the list and Python! When posting code in the future I recommend
posting in plain text and not "rich" text or HTML. If you are using
Yahoo! via web interface you can do this by the following link.
> def print_a_line(line_count, f):
> print line_count, f.readline()
> I understand that line_count counts the number of lines in the Python prog,
> and that we are creating a function, and that 'f' stands for file etc, but I
> can't get my head around what the function does.
line_count in this function can be anything. It is not actually
doing any counting or any work. All this function does is print whatever
information is in line_count (I assume it would be the current line number),
then it retrieves exactly one line from the file f and then prints that
Let us assume that the following multi-line string is what is contained in
file f. Some examples of what this function would print are shown below.
'''This is the first line.
And this is the second line.
>>> print_a_line(1, f )
1 This is the first line.
>>> print_a_line('line 2:', f )
line 2: And this is the second line.
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
Tutor maillist - Tutor <at> python.org
To unsubscribe or change subscription options: