[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Sticky Variables: Terrain Loading



On Wed, 12 Mar 2008 06:59:52 +0200, Toni Alatalo <antont@xxxxxxxxxxxxx>
wrote:
> note that you are changing y inside the inner loop with x, so when
> iterating the x values the y is not reset by the y iteration but i
> guess stays what you define it to be.
> 
> does this fully explain the peculiar behavior that you got .. and it
> had nothing to do with the 'terrain' reference being reused?

Although it surprises me that the loop wouldn't reset y to be the next
number in the sequence at the start of each iteration, that behavior does
seem to explain what happened.

> therefore, when you get down to "self.land.append(terrain)", after such
> a if-elif-else structure where a new string object is always created,
> 'terrain' is *in principle* never the same object. *but*, like we
> already saw with smallish integers, there's a similar re-use
> optimization for strings apparently:
>  >>> long1 = "water is wet"
>  >>> long2 = "water is wet"
>  >>> long1 is long2
> False
>  >>> short1 = "water"
>  >>> short2 = "water"
>  >>> short1 is short2
> True

This really surprises me! I hadn't known about these automatic
optimizations. Yes, I know that "== != is", but the rest of it is news to
me.

Kris