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

Re: [pygame] Fwd: [Tutor] A more Pythonic way to do this



Hi Denise.

I would just generally recommend the rule of thumb of not using class
attributes unless you really need them (implementing a Singleton or
something).  You're using class attributes again here:

>     Enemy.initialx = (cols*60)+20
>     Enemy.initialy = (rows*40)+30
>     enemyship_sprites.add(Enemy(Enemy.initialx, Enemy.initialy, level))
>     print Enemy.initialx,
>     print Enemy.initialy

Try to avoid writing Enemy.initalx anywhere in your code.  You could
rewrite the above as this:

      newX = (cols*60)+20
      newY = (cols*60)+20
      newEnemy = Enemy(newX, newY, level)
      enemyship_sprites.add( newEnemy )

It's also a bit more readable like this, I think.  (Another rule of thumb:
never sacrifice clarity for brevity)

-sjbrown