Re: Generator using item[n-1] + item[n] memory

2014-02-15 Thread Steven D'Aprano
On Fri, 14 Feb 2014 22:21:11 -0500, Roy Smith used a generator: print g1.next() Roy, unless you're stuck with Python 2.5 (or older!), you ought to use the built-in function next(g1) rather than directly call the next method. Not only is this the recommended way to do it, but it's also more

Re: Generator using item[n-1] + item[n] memory

2014-02-15 Thread Peter Otten
Chris Angelico wrote: On Sat, Feb 15, 2014 at 6:27 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Fri, Feb 14, 2014 at 8:31 PM, Nick Timkovich prometheus...@gmail.com wrote: OK, now the trick; adding `data = None` inside the generator works, but in my actual code I wrap my generator inside of

Re: Generator using item[n-1] + item[n] memory

2014-02-15 Thread Mark Lawrence
On 15/02/2014 03:31, Nick Timkovich wrote: OK, now the trick; adding `data = None` inside the generator works, but in my actual code I wrap my generator inside of `enumerate()`, which seems to obviate the fix. Can I get it to play nice or am I forced to count manually. Is that a feature? On

Generator using item[n-1] + item[n] memory

2014-02-14 Thread Nick Timkovich
I have a Python 3.x program that processes several large text files that contain sizeable arrays of data that can occasionally brush up against the memory limit of my puny workstation. From some basic memory profiling, it seems like when using the generator, the memory usage of my script balloons

Re: Generator using item[n-1] + item[n] memory

2014-02-14 Thread Ian Kelly
On Fri, Feb 14, 2014 at 3:27 PM, Nick Timkovich prometheus...@gmail.com wrote: I have a Python 3.x program that processes several large text files that contain sizeable arrays of data that can occasionally brush up against the memory limit of my puny workstation. From some basic memory

Re: Generator using item[n-1] + item[n] memory

2014-02-14 Thread Nick Timkovich
Ah, I think I was equating `yield` too closely with `return` in my head. Whereas `return` results in the destruction of the function's locals, `yield` I should have known keeps them around, a la C's `static` functions. Many thanks! -- https://mail.python.org/mailman/listinfo/python-list

Re: Generator using item[n-1] + item[n] memory

2014-02-14 Thread Roy Smith
In article mailman.6952.1392433921.18130.python-l...@python.org, Nick Timkovich prometheus...@gmail.com wrote: Ah, I think I was equating `yield` too closely with `return` in my head. Whereas `return` results in the destruction of the function's locals, `yield` I should have known keeps them

Re: Generator using item[n-1] + item[n] memory

2014-02-14 Thread Nick Timkovich
OK, now the trick; adding `data = None` inside the generator works, but in my actual code I wrap my generator inside of `enumerate()`, which seems to obviate the fix. Can I get it to play nice or am I forced to count manually. Is that a feature? On Fri, Feb 14, 2014 at 9:21 PM, Roy Smith

Re: Generator using item[n-1] + item[n] memory

2014-02-14 Thread Ian Kelly
On Fri, Feb 14, 2014 at 8:31 PM, Nick Timkovich prometheus...@gmail.com wrote: OK, now the trick; adding `data = None` inside the generator works, but in my actual code I wrap my generator inside of `enumerate()`, which seems to obviate the fix. Can I get it to play nice or am I forced to

Re: Generator using item[n-1] + item[n] memory

2014-02-14 Thread Chris Angelico
On Sat, Feb 15, 2014 at 6:27 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Fri, Feb 14, 2014 at 8:31 PM, Nick Timkovich prometheus...@gmail.com wrote: OK, now the trick; adding `data = None` inside the generator works, but in my actual code I wrap my generator inside of `enumerate()`, which