I'm pretty sure the issue is that your Message
class is defined in a different module than where your topology
variable is. So called "global" variables in Python are not really global (in the sense that there's just one global namespace), but just at the top of a specific module's namespace. So the global variable topology
in your main module's namespace is not accessible as a global variable from a different module.
My suggestion for working around this by passing the topology value to the Message
as a parameter to the __init__
method. If the message is being created by something other than your own code (e.g. by your Node
class), you might need to pass it around a bit more, so that it will be available when needed.
If that is not possible, you might be able to put the topology value in the namespace of a module that can be imported by your Message
code. This can get messy though, as circular imports can break things if you're not careful.