On 19 September 2013 15:38, Peter Otten <__pete...@web.de> wrote:
>> While running the above python.exe was using 6MB of memory (according
>> to Task Manager). I believe this is because tee() works as follows
>> (which I made up but it's how I imagine it).
>
> [...]
>
>> However, when I ran the abo
Oscar Benjamin wrote:
> $ cat tee.py
> #!/usr/bin/env python
>
> import sys
> from itertools import tee
>
> items = iter(range(int(sys.argv[1])))
>
> while True:
> for x in items:
> items, discard = tee(items)
> break
> else:
> break
>
> print(x)
>
> $ time py
On 19 September 2013 08:23, Peter Otten <__pete...@web.de> wrote:
> Roy Smith wrote:
>>
>> I believe by "Peter's version", you're talking about:
>>
>>> from itertools import islice, tee
>>>
>>> with open("tmp.txt") as f:
>>> while True:
>>> for outer in f:
>>> print outer,
>
Roy Smith wrote:
>> Dave Angel wrote (and I agreed with):
>>> I'd suggest you open the file twice, and get two file objects. Then you
>>> can iterate over them independently.
>
>
> On Sep 18, 2013, at 9:09 AM, Oscar Benjamin wrote:
>> There's no need to use OS resources by opening the file twi
Although "tee" is most certainly preferable because IO is far slower
than the small amounts of memory "tee" will use, you do have this
option:
def iterate_file_lines(file):
"""
Iterate over lines in a file, unlike normal
iteration this allows seeking.
"""
On Wed, 18 Sep 2013 04:12:05 -0700, nikhil Pandey wrote:
> hi,
> I want to iterate over the lines of a file and when i find certain
> lines, i need another loop starting from the next of that "CERTAIN" line
> till a few (say 20) lines later. so, basically i need two pointers to
> lines (one for ou
On Wed, 18 Sep 2013 05:14:23 -0700, nikhil Pandey wrote:
> I want to iterate in the inner loop by reading each line till some
> condition is met.how can i do that. Thanks for this code.
while not condition:
read line
Re-write using Python syntax, and you are done.
--
Steven
--
https://
On 18/9/2013 10:36, Roy Smith wrote:
>> Dave Angel wrote (and I agreed with):
>>> I'd suggest you open the file twice, and get two file objects. Then you
>>> can iterate over them independently.
>
>
> On Sep 18, 2013, at 9:09 AM, Oscar Benjamin wrote:
>> There's no need to use OS resources by op
On Sep 18, 2013, at 5:07 AM, nikhil Pandey wrote:
> On Wednesday, September 18, 2013 4:51:51 PM UTC+5:30, Chris Angelico wrote:
>> On Wed, Sep 18, 2013 at 9:12 PM, nikhil Pandey
>> wrote:
>>
>>> hi,
>>
>>> I want to iterate over the lines of a file and when i find certain lines, i
>>> need
> Dave Angel wrote (and I agreed with):
>> I'd suggest you open the file twice, and get two file objects. Then you
>> can iterate over them independently.
On Sep 18, 2013, at 9:09 AM, Oscar Benjamin wrote:
> There's no need to use OS resources by opening the file twice or to
> screw up the IO c
On 18 September 2013 13:56, Roy Smith wrote:
>
>> > On Wed, Sep 18, 2013 at 9:12 PM, nikhil Pandey
>> > wrote:
>> >> hi,
>> >> I want to iterate over the lines of a file and when i find certain lines,
>> >> i need another loop starting from the next of that "CERTAIN" line till a
>> >> few (say 20
> > On Wed, Sep 18, 2013 at 9:12 PM, nikhil Pandey
> > wrote:
> >> hi,
> >> I want to iterate over the lines of a file and when i find certain lines,
> >> i need another loop starting from the next of that "CERTAIN" line till a
> >> few (say 20) lines later.
> >> so, basically i need two point
nikhil Pandey wrote:
> On Wednesday, September 18, 2013 5:14:10 PM UTC+5:30, Peter Otten wrote:
> I want to iterate in the inner loop by reading each line till some
> condition is met.how can i do that. Thanks for this code.
That's not what I had in mind when I asked you to
>> describe your act
On Wednesday, September 18, 2013 5:14:10 PM UTC+5:30, Peter Otten wrote:
> nikhil Pandey wrote:
>
>
>
> > hi,
>
> > I want to iterate over the lines of a file and when i find certain lines,
>
> > i need another loop starting from the next of that "CERTAIN" line till a
>
> > few (say 20) lines
On Wednesday, September 18, 2013 4:51:51 PM UTC+5:30, Chris Angelico wrote:
> On Wed, Sep 18, 2013 at 9:12 PM, nikhil Pandey
> wrote:
>
> > hi,
>
> > I want to iterate over the lines of a file and when i find certain lines, i
> > need another loop starting from the next of that "CERTAIN" line
nikhil Pandey wrote:
> hi,
> I want to iterate over the lines of a file and when i find certain lines,
> i need another loop starting from the next of that "CERTAIN" line till a
> few (say 20) lines later. so, basically i need two pointers to lines (one
> for outer loop(for each line in file)) and
On 18/9/2013 07:21, Chris Angelico wrote:
> On Wed, Sep 18, 2013 at 9:12 PM, nikhil Pandey
> wrote:
>> hi,
>> I want to iterate over the lines of a file and when i find certain lines, i
>> need another loop starting from the next of that "CERTAIN" line till a few
>> (say 20) lines later.
>> so
On Wed, Sep 18, 2013 at 9:12 PM, nikhil Pandey wrote:
> hi,
> I want to iterate over the lines of a file and when i find certain lines, i
> need another loop starting from the next of that "CERTAIN" line till a few
> (say 20) lines later.
> so, basically i need two pointers to lines (one for out
18 matches
Mail list logo