0
Hello, I’m writing the code for a university project, but when I try to import dependencies to some files, from Error.
I created some package’s that have files that have dependencies, but they don’t find these files.
The entire project is on github, in the same structure as my machine, to help with an eventual solution.
Code repository: ( GITHUB )
File structure:
Start by running the run.py
from agents.agent_defender import Defender
d = Defender()
However the following Error appears.
Traceback (most recent call last):
File "/home/davi/PycharmProjects/AAMAS/run.py", line 1, in <module>
from agents.agent_defender import Defender
File "/home/davi/PycharmProjects/AAMAS/agents/agent_defender.py", line 1, in <module>
from agents.agent import Agent
File "/home/davi/PycharmProjects/AAMAS/agents/agent.py", line 1, in <module>
from .states.state import State
File "/home/davi/PycharmProjects/AAMAS/agents/states/state.py", line 2, in <module>
from agents.agent import Agent
ImportError: cannot import name 'Agent'
File -> agent.py (agent_defender is the same Thing)
from .states.state import State
"""
Is basic reference of agent.
"""
class Agent(object):
state = None
mail = None # We use mail, to easily synchronize the agents per turn.
neighbors = None # The another agent's of this agent can communicate.
def __init__(self):
# check integrity of agent, when is crate
raise NotImplementedError("subclasses must override __init__ method!\nYou can't instantiate this class!\n")
def __change_state(self, state):
# Responsible to change the agent state.
raise NotImplementedError("subclasses must override change_state method!\n")
def __valid_state(self):
# check integrity of agent state, when is crate
if not self.state:
raise TypeError("The agent had have a valid state!\n")
if isinstance(self.state, State):
raise TypeError("The state of this agent not is instance of ' State class '!\n")
def __str__(self):
# Return a basic str info about the agent.
return self.state.get_string_info()
def get_info(self):
return self.state.get_info()
def recive_msg(self, data):
# Recive msg, and do what's necessary, whit the data input and put things on mail.
raise NotImplementedError("subclasses must override recive_msg method!\n")
def send_msg(self, agent):
# Send msg, whit data to another agent.
raise NotImplementedError("subclasses must override send_msg method!\n")
def do(self):
# Is the principal method of the agent, because, the interpret the agent variables, and :
# decide the state, what msg send's, read mail, made actions.
# The method 'do', pass to state him self, and the state, using the parameters of the agent chose the action.
# Ex.: self.state.do(self)
self.state.do(self)
File -> state.py
from interface.model import model
from agents.agent import Agent
class State(object):
letter = None
Meaning = None
def __init__(self):
raise NotImplementedError("subclasses must override __init__ method!\nYou can't instantiate this class!\n")
def get_info(self):
# return info about the state to use on terminal package.
raise NotImplementedError("subclasses must override get_info method!\n")
def get_string_info(self):
# This method implement's the output of the agent state.
# Using the method model to had a eas pattern of string, receive '1 char' to represent the state
raise NotImplementedError("subclasses must override string_info method!\n")
def legend(self):
# This method return (letter, meaning), info about what letter and your about meaning this state.
# letter and meaning is string.
# And if the letter is not be unique, the will raise a Error.
raise NotImplementedError("subclasses must override legend method!\n")
def do(self, agent: Agent):
# this method, receive an agent, interpreter his values and made all necessaries actions.
raise NotImplementedError("subclasses must override legend method!\n")
If any good soul can show me my mistake,.
Adding out of reply, a while ago I wrote in mine blog something very basic about building modules in Python that might help.
– Giovanni Nunes
I’ll give it a try and feed back.
– Davi Mello
Tested it didn’t work.
– Davi Mello
I supplemented it with some more information, if you want the code skeleton I built.
– Giovanni Nunes
I will implement, and give feedback. Thank you very much for your attention.
– Davi Mello