python - How do you print an attribute of a subclass? -


i making text based game , file using establishing attributes of rooms. whenever try test file out printing room description of room3 (print room3.desc) receive error: attributeerror: type object 'room3' has no attribute 'desc'

  class room:     def __init__(self, x, y, desc):         self.x=x         self.y=y         self.desc=desc    class room1(room):     def __init__(self, x, y, desc):         super(room1, self).__init__()         self.x=0         self.y=0         self.desc="""          metal hallway         place dimly lit , cool         ----------------------------------------------------         stand in middle of intersection in metal room.         there blue glowing lamps lighting area up. there         sign on wall.         ----------------------------------------------------         obvious exits:east, north"""  class room2(room):     def __init__(self, x, y, desc):         super(room2, self).__init__()         self.x=1         self.y=0         self.desc="""          thacker's main control room         place lit , cool         ----------------------------------------------------         there multiple panels throughout variety of levers , buttons.         people stand in uniforms infront of computers, scattered throughout room.         there glass window here revealing space.         thacker sitting here in of room in large chair.         ----------------------------------------------------         obvious exits:west"""  class room3(room):     def __init__(self, x, y, desc):         super(room3, self).__init__()         self.x=0         self.y=1         self.desc== """           large hanger bay         place lit , cool         ----------------------------------------------------         there variety of mobile suits here         ----------------------------------------------------         obvious exits:south"""   print("%s" % room3.desc) 

you're trying access desc via reference class itself, desc defined in constructor, means it's available in instances of class.

this points general problem code: you're defining subclasses of room, when want create instances of class room:

room1 = room(0, 0, """a metal hallway...") room2 = room(1, 0, """thacker's main control room...") etc... 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -