reading from sys.stdin
Michael Bentley
michael at jedimindworks.com
Fri Apr 13 06:33:25 EDT 2007
On Apr 13, 2007, at 4:47 AM, 7stud wrote:
> On Apr 13, 3:36 am, "7stud" <bbxx789_0... at yahoo.com> wrote:
>>
>>> It is if the file is smaller than the buffer size.
>>
>> How is that relevant?
>>
>
> If I put 100 lines of text in a file with each line having 50
> characters, and I run this code:
>
> import sys
>
> lst = []
> for line in open("aaa.txt"):
> print "an iteration"
> lst.append(line)
> break
>
> print lst
>
>
> The output is:
>
> $ python test1.py
>
> an iteration
> ['helleo haljdfladj ahdflasdjf ds hdljfalsdjfdsljfds \n']
>
> It seems clear to me that the whole file wasn't first read into a
> buffer before the code started processing the data.
The break statement causes it to bail after the first iteration, so
that doesn't really prove your point. For example:
lst = []
for line in ['we', 'all live', 'in a yellow', 'submarine']:
print "an iteration"
lst.append(line)
break
print lst
The output is:
an iteration
['we']
More information about the Python-list
mailing list