beginner, idiomatic python

bambam david at asdf.asdf
Mon Aug 27 05:18:14 CEST 2007

Thank you, I have been through the tutorial several times, I guess
I'm just not smart enough. Perhaps I have been led astray by what
I read here?

My code started like this:

for i in range(self.parent.GetPageCount()):

I was asked:

>Does page count change? i.e. is it necessary to retrieve it in every loop

Is self.parent.GetPageCount() 'retrieved every loop'?


"Gabriel Genellina" <gagsl-py2 at> wrote in message 
news:mailman.13.1188182594.28954.python-list at
> En Sun, 26 Aug 2007 22:58:35 -0300, bambam <david at asdf.asdf> escribi?:
>> Ok, many environments are capable of cached evaluation
>> of functions without variable parameters so
>>     range(5)
>> is cached, but
>>     range(v) is re-evaluated every time. Is this defined
>> behaviour?
> The range builtin function returns a list, and lists are mutable objects, 
> so it must return a *different* list each time.
>> That is, is it defined what Python does for
>>     for i in f()
>> I'm sure it must be, but I haven't seen it yet. If I have
>> a user defined function returning a range, is it defined
>> that the range function is called on every loop? If I
>> have a function returning a range taking a parameter,
>>     for i in f(v)
>> is it defined that the variable is evaluated for every loop?
> Find all the (mostly negative) answers yourself in 
> <>
> -- 
> Gabriel Genellina

More information about the Python-list mailing list