Newbie: calling the originating class ...

donkeyboy fivenastydisco at hotmail.com
Tue Aug 15 03:13:15 EDT 2006


This is probably very straightforwards to someone with experience, but
I will try to explain my predicament:

I'm trying to code a simulation, where you have a Simulation class that
knows everything about the simulation, and in turn classes that the
Simulation calls when it wants to make new instances -- for the time
being, let's call the called classes Agents (sorry, saw the Matrix
again last night!).

In the Simulation class, there's information about the simulation that
each Agent wants to know. As such, I wrote a method in the Simulation
class for the Agents to call, to get the said required information.
However, I can't figure out a way for the Agents to call the
Simulations methods -- is this even possible?

The pseudo-code I'm using is as follows:

s = Simulation()

class Simulation:
    # create a number of agents
    ...
    # Simulation information
    important_stuff = 10

    def showImportant(self):
    return important_stuff

class Agents:
    my_stuff = s.showImportant

... which fails: I get errors saying the global name 's' is not
defined. Any thoughts? Is what I'm trying to do even possible, or
should I be doing something else?

Thanks in advance!!

DB




More information about the Python-list mailing list