[Tutor] re adlines, read, and my own get_contents()
Kent Johnson
kent37 at tds.net
Thu Jun 19 11:37:20 CEST 2008
On Thu, Jun 19, 2008 at 2:44 AM, John [H2O] <washakie at gmail.com> wrote:
>
> I've defined:
>
> def get_contents(infile=file_object):
> """ return a list of lines from a file """
> contents=infile.read()
> contents = contents.strip().split('\n')
> return contents
> I think I understand the differences, but can someone tell me if there's any
> difference between what I define and the readlines() method?
readline() and readlines() include the trailing newline in the lines
they return; your function does not.
readline() and readlines() don't strip leading and trailing space.
contents = contents.splitlines(True) would duplicate readlines() I think.
Kent
More information about the Tutor
mailing list