new linereading standard?

Al-Amerrho H. Amerin al_amerin at yahoo.com
Mon Apr 24 23:28:09 EDT 2000


Pete Shinners wrote:

>
> now i can code in a preferred style
>
> myfile = open('myfile.txt', 'r')
> for line in filelines(myfile):
>     print line
> myfile.close()
>
> as opposed to
>
> myfile = open('myfile.txt', 'r')
> while 1:
>     line = myfile.readline()
>     if not line: break
>     print line
> myfile.close()
>
>
> _____Pete Shinners______
>    pete at visionart.com

A beginner myself, I would write it like this:

inputlines = open('myfile.txt').readlines()
for line in inputlines:
    print line

Instead of the 'while 1: ....break' thingy.

Al-




More information about the Python-list mailing list