[Tutor] Module Packages
amk at amk.ca
amk at amk.ca
Thu Oct 30 14:48:07 EST 2003
On Wed, Oct 29, 2003 at 11:12:46PM -0000, Zak Arntson wrote:
> But it looks like I'll have to:
> plr = Entity.Player.Player()
> zom1 = Entity.Monster.Zombie.Zombie()
> zom2 = Entity.Monster.Zombie.Zombie()
Use 'from ... import':
from Pyrl.Entity.Player import Player
from Pyrl.Entity.Monster.Zombie import Zombie
'from ... import *' is considered poor practice, because it imports a whole
bunch of names from the module, but most people have nothing against
importing a few specified names.
Alan Gauld is correct that it's often clearer to have multiple classes in a
file; for example, "from Pyrl.Entity.Monster import Zombie, Vampire" would
be tidier. That depends on the length of each class; if the Zombie class is
500 lines long, you're probably going to want to put it in a file of its
own, but if it's 3 lines or 20 lines or maybe 100 lines, you can put
multiple monster classes in a file without things becoming too ungainly.
--amk
More information about the Tutor
mailing list