Why does this work?

a.clarke11 a.clarke11 at pop.ntlworld.com
Wed Mar 27 07:31:16 EST 2002


Hi
I defined a class, and made an instance. The class sis not have a
def__init__() line. In the class, I defined a function  f(x) and an list
object X.tiles. Why can I later call instancename.f, and
instancename.tiles?
I thought the class had to have a def__init__() line in it for this to
work? I would be glad if somebody could spell this out for me, although
it is working perfectly well in the finished program!
The relevant code is:
class Player:

 import random
 Tiles=[]
 Sound="click"
 Win="yippee"
 playlist=[]
 def chooseTiles(x):
  import random
  random.shuffle(Setup.r)
  x.Tiles=[]
  while len(x.Tiles)<7:
   l=0
   l=Setup.r.pop(random.uniform(1,len(Setup.r)))
   x.Tiles.append(l)
  x.Tiles.sort()
 playstring=[]





Porky=Player()
Porky.chooseTiles()

Thanks in anticipation
Tony




More information about the Python-list mailing list