itens = []
lugares = []
lugar = None
from pickle import dumps
# Definição das funções:
def adlugar(nome, lookmsg, passagens, objs = None):
global lugares
global dic
dic = dumps(nome)
dic = {"nome": nome, "look": lookmsg, "passagens": passagens.split(" # ")}
if objs:
itens = objs.split(" # ")
dic["invent"] = itens
lugares.append(nome.lower())
def aditen(nome, lookmsg, getmsg, pegavel = "não"):
global itens
global dic
dic = dumps(nome)
dic = {"nome": nome, "look": lookmsg, "get": getmsg, "pg": pegavel}
itens.append(nome.lower())
def look(obj):
global itens
global lugar
if obj in itens:
obj = obj.lower()
obj = dumps(obj)
if obj in lugar["invent"]:
return(obj[look])
lugar = dumps("casa")
adlugar("casa", "casa.", "quintal", "livro")
aditen("livro", "livro", "livro", "sim")
look("livro")
I'm having trouble with dictionary manipulation. I defined a function that creates dictionaries, and another one that invokes values from indexes. But within the function that calls the values I get the following error:
if obj in lugar["invent"]: TipeError: byte indices must be integers or slices, not str
First, when I use the adlugar () function it should create a dictionary, in this case: home = {"name": "home", "look": "home", " , "invent": "book"} The aditen function should create a dictionary book = {"name": "book", "look": "book", "get": "book", "pg": "yes"}. Note that both functions use the name attribute to create a dumps (name) variable for the dictionary (the reason is that you can not create string variables, and my solution was to use the dumps to turn them into byte sequences). The look function uses the place variable to know in which dictionary it should check the "invent" index. If the object is in this index, it returns what is in the "look" index of the obj. However, when I invoke the command, it says that my index can not be a string, but an integer or a slice, which are list indexes. does that mean he's treating the bastards as if they were ready?