Edited:
I want to generate N-number of agents. Each agent will have a name, so I create a random name from names and assigned it to class Agent.
After I run the model, I want to get the list of my agents name.
This is from mesa:
import names
from mesa import Agent, Model
from mesa.time import RandomActivation
class Agent(Agent):
def __init__(self, name):
self.name= names.get_full_name()
self.wealth = 1
def step(self):
pass
class Model(Model):
def __init__(self, N):
self.num_agents = N
self.schedule = RandomActivation(self)
for i in range(N):
a = MoneyAgent(i)
self.schedule.add(a)
def step(self):
self.schedule.step()
on interactive session
gow = MoneyModel(10)
gow.step()
atr = list([a for a in MoneyAgent.name])
print(atr)
I got this error:
File "C:\src__init__.py", line 7, in atr = list([a for a in MoneyAgent.name]) AttributeError: type object 'MoneyAgent' has no attribute 'name'
How to fix it?
Here's my interpretation of your problem: You're creating a
MoneyModel
object which contains a collection ofMoneyAgent
objects stored in a collection-like object referred to asMoneyModel.schedule
, and you want alist
of thename
s of eachMoneyAgent
object within yourMoneyModel.schedule
collection.Assuming
MoneyModel.schedule
behaves as an iterable object, the following should work: