Passing data between objects and calling all objects of a class in turn

Discussion in 'Python' started by ghoetker, Aug 25, 2010.

  1. ghoetker

    ghoetker Guest

    I'm a fairly new Python coder, learning along with my son (actually,
    hopefully a bit ahead of him...). We're stuck on something.

    As part of solving a backwards induction problem (purely as a learning
    experience, we are geeks), we are going to create N objects, each of
    the class "interview". We will first create the N_th interview, which
    will calculate, based on data we pass to it, its expected payoff
    value. We will then create interview N-1, which needs to know the
    expected payoff of interview N in order to determine a decision and
    then calculate its own expected payoff. We then create interview N-2,
    which needs to know the expected payoff of interview N-1, etc., until
    we reach interview 1.

    1. How can we best (that is, most Pythonically) let interview N-1
    know the expected value of interview N and so on. One way would be to
    define a variable "payoff_of_continuing" which gets set to the
    expected value of interview N and is passed to interview N-1 when is
    created. Interview N-1 then resets "payoff_of_continuing", which is
    passed to interview N-2 when it is created, etc. Is there a more
    Pythonic approach?

    2. When we want to output the results of the analysis, how do we most
    Pythonically get each interview object in turn to report its identity,
    the result of its decision and its expected payoff (e.g., For
    interview 3, stop if you interview a good candidate. This interview's
    expected value is 2.5). I know how to do the reporting part
    (print....), it's the "getting each interview object in turn to..."
    part that I'm unsure about. We could have each interview report as it
    is created, but I'm wondering if the splitting it into "Create all the
    objects" and "Report the results from all the objects" is sensible.
    For one thing, it would allow compiling the results into a table, etc.

    I really appreciate any input. I'm a competent procedural programmer
    (albeit not primarily in Python), but a dabbler in object oriented
    programming (we've already done this problem procedurally, but want to
    try it again as OOP). Thank you!!
     
    ghoetker, Aug 25, 2010
    #1
    1. Advertising

  2. ghoetker

    MRAB Guest

    Re: Passing data between objects and calling all objects of a classin turn

    On 25/08/2010 03:49, ghoetker wrote:
    > I'm a fairly new Python coder, learning along with my son (actually,
    > hopefully a bit ahead of him...). We're stuck on something.
    >
    > As part of solving a backwards induction problem (purely as a learning
    > experience, we are geeks), we are going to create N objects, each of
    > the class "interview". We will first create the N_th interview, which
    > will calculate, based on data we pass to it, its expected payoff
    > value. We will then create interview N-1, which needs to know the
    > expected payoff of interview N in order to determine a decision and
    > then calculate its own expected payoff. We then create interview N-2,
    > which needs to know the expected payoff of interview N-1, etc., until
    > we reach interview 1.
    >
    > 1. How can we best (that is, most Pythonically) let interview N-1
    > know the expected value of interview N and so on. One way would be to
    > define a variable "payoff_of_continuing" which gets set to the
    > expected value of interview N and is passed to interview N-1 when is
    > created. Interview N-1 then resets "payoff_of_continuing", which is
    > passed to interview N-2 when it is created, etc. Is there a more
    > Pythonic approach?
    >

    I hope you don't mean that "payoff_of_continuing" is a global variable
    which is set by the instance when it's created. The Pythonic way would
    be to create the instance and then ask it what it's payoff is so that
    you then know what to pass in when you create the next instance.

    > 2. When we want to output the results of the analysis, how do we most
    > Pythonically get each interview object in turn to report its identity,
    > the result of its decision and its expected payoff (e.g., For
    > interview 3, stop if you interview a good candidate. This interview's
    > expected value is 2.5). I know how to do the reporting part
    > (print....), it's the "getting each interview object in turn to..."
    > part that I'm unsure about. We could have each interview report as it
    > is created, but I'm wondering if the splitting it into "Create all the
    > objects" and "Report the results from all the objects" is sensible.
    > For one thing, it would allow compiling the results into a table, etc.
    >

    Put the objects into a list when you create them and then iterate through
    them, asking each to print its report.

    > I really appreciate any input. I'm a competent procedural programmer
    > (albeit not primarily in Python), but a dabbler in object oriented
    > programming (we've already done this problem procedurally, but want to
    > try it again as OOP). Thank you!!
     
    MRAB, Aug 25, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dave wanta
    Replies:
    0
    Views:
    425
    dave wanta
    Jul 4, 2003
  2. E11
    Replies:
    1
    Views:
    4,955
    Thomas Weidenfeller
    Oct 12, 2005
  3. =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=

    2.0: Turn on all available health monitoring

    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=, Aug 3, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    322
    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=
    Aug 3, 2006
  4. Moderator
    Replies:
    0
    Views:
    334
    Moderator
    Aug 7, 2006
  5. Malciah
    Replies:
    8
    Views:
    470
    James Kanze
    Apr 19, 2007
Loading...

Share This Page