Python- how to get list of self variables in a class consist of N-self

后端 未结 1 922
夕颜
夕颜 2021-01-29 08:48

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

相关标签:
1条回答
  • 2021-01-29 09:37

    Here's my interpretation of your problem: You're creating a MoneyModel object which contains a collection of MoneyAgent objects stored in a collection-like object referred to as MoneyModel.schedule, and you want a list of the names of each MoneyAgent object within your MoneyModel.schedule collection.

    Assuming MoneyModel.schedule behaves as an iterable object, the following should work:

    atr = [agent.name for agent in gow.schedule]
    
    0 讨论(0)
提交回复
热议问题