new linereading standard?
Radovan Garabik
garabik at center.fmph.uniba.spam.sk
Tue Apr 25 07:05:20 EDT 2000
Al-Amerrho H. Amerin <al_amerin at yahoo.com> wrote:
> 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.
...with the disadvantage that this will read the whole
file into memory, which can be a bit difficult to handle when it
is several MB long...
--
----------------------------------------------------------
| Radovan Garabik http://www.fmph.uniba.sk/~garabik/ |
| __..--^^^--..__ garabik at center.fmph.uniba.sk |
----------------------------------------------------------
More information about the Python-list
mailing list