[Tutor] (no subject)

Britt Green cheshire_cat_sf@yahoo.com
Sun, 24 Feb 2002 20:42:34 -0800 (PST)


Can anyone tell me why I get this error on the following code, and what
a good solution for it would be?

>>> 
--> e
You are in the foyer
--> w
Traceback (most recent call last):
  File "C:/WINNT/Profiles/bgreen/Desktop/kode/fourth.py", line 37, in ?
    if playerLoc.exits.has_key(command[0]):
AttributeError: 'str' object has no attribute 'exits'

>>> 

import string

class Room:
    def __init__(self, name, exits):
        self.name = name
        self.exits = exits
        self.items = []

    def __str__(self):
        return self.name

porch = Room('porch', {'e':'foyer'})
foyer = Room('foyer', {'w':'porch', 'e':'dining room'})
dining = Room('dining room', {'w':'foyer'})

commands = ['n','s','e','w']
playerLoc = porch

while 1:
    command = string.split(raw_input('--> '))
    if command[0] in commands:
        if playerLoc.exits.has_key(command[0]):
            playerLoc = playerLoc.exits.get(command[0])
            print "You are in the", playerLoc

=====
"The ocean, she is strange and wondrous, filled with animals that disturb even a Frenchman."

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com