Re: [Tutor] generators

2012-04-04 Thread bob gailer
To Joel's and Wesley's valuable comments I add: Calling a generator function returns a /generator object/. >>> def x(n): ... for i in range(n): yield i ... >>> y = x(3) >>> print y A generator object can be used instead of some other "iterable" (e.g.) in for statements. >>> for i in y:print

Re: [Tutor] generators

2012-04-03 Thread wesley chun
> On Tue, Apr 3, 2012 at 2:38 PM, mike jackson wrote: > I am trying understand python and have done fairly well, So for it has been > easy to learn and is concise.  However I seem to not quite understand the use > of a generator over a function(I am familiar with functions [other languages > an

Re: [Tutor] generators

2012-04-03 Thread Joel Goldstick
On Tue, Apr 3, 2012 at 2:38 PM, mike jackson wrote: > I am trying understand python and have done fairly well, So for it has been > easy to learn and is concise.  However I seem to not quite understand the use > of a generator over a function(I am familiar with functions [other languages > and

Re: [Tutor] generators

2012-04-03 Thread Abhishek Pratap
Hey Mike The following link should help you. http://www.dabeaz.com/generators/ . Cool slide deck with examples from David Beazley's explanation of generators. -A On Tue, Apr 3, 2012 at 11:38 AM, mike jackson wrote: > I am trying understand python and have done fairly well, So for it has be

[Tutor] generators

2012-04-03 Thread mike jackson
I am trying understand python and have done fairly well, So for it has been easy to learn and is concise.  However I seem to not quite understand the use of a generator over a function(I am familiar with functions [other languages and math]).  To me (excepting obvious syntax differences) a gener

Re: [Tutor] Generators

2007-07-24 Thread Michael Sparks
On Tuesday 24 July 2007 13:11, Kent Johnson wrote: > 'while 1' is optimized to just a jump - the compiler recognizes that the > test is not needed and skips it. 'while True' requires looking up the > value of the name 'True' and testing it. This may seem counter intuitive, but the reason for this

Re: [Tutor] Generators

2007-07-24 Thread Kent Johnson
Tiger12506 wrote: >> I am new to Python but not new to programming languages. I have seen this >> "while 1" a lot. In fact in other languages I would expect "while 1" to >> be >> the same as "while TRUE". The predefined constants True and False were not added to Python until version 2.3. Befor

Re: [Tutor] Generators

2007-07-23 Thread Luke Paireepinart
Tiger12506 wrote: >> I am new to Python but not new to programming languages. I have seen this >> "while 1" a lot. In fact in other languages I would expect "while 1" to >> be >> the same as "while TRUE". I have used that in other languages, but in the >> definition below I would expect the "yi

Re: [Tutor] Generators

2007-07-23 Thread Tiger12506
> I am new to Python but not new to programming languages. I have seen this > "while 1" a lot. In fact in other languages I would expect "while 1" to > be > the same as "while TRUE". I have used that in other languages, but in the > definition below I would expect the "yield b..." to continue o

Re: [Tutor] Generators

2007-07-23 Thread Tiger12506
> Please forgive my instrusion with some simple questions. I don't have any > formal training in programming so I have to get some guidance to some > terminology from time to time. What is a generator and what is its > purpose? Think of a generator as a list whose contents haven't been finished

Re: [Tutor] Generators

2007-07-19 Thread Kent Johnson
Doug Glenn wrote: > Greetings all, > > Please forgive my instrusion with some simple questions. I don't have > any formal training in programming so I have to get some guidance to > some terminology from time to time. What is a generator and what is its > purpose? If you are that new to prog

[Tutor] Generators

2007-07-19 Thread Doug Glenn
Greetings all, Please forgive my instrusion with some simple questions. I don't have any formal training in programming so I have to get some guidance to some terminology from time to time. What is a generator and what is its purpose? I am planning on building a DVD catalog utility for Linux i