Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Passing data between objects and calling all objects of a class in turn

Reply
Thread Tools

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

 
 
ghoetker
Guest
Posts: n/a
 
      08-25-2010
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!!
 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      08-25-2010
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!!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class Templates, Pointers, and transferring data between class objects Malciah C++ 8 04-19-2007 07:49 AM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Turn-Key Calling Card Solution W/ Cisco Gateway (8T1/E1) DoretelCom VOIP 0 07-07-2006 07:01 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Re: Passing objects between pages and frames... dave wanta ASP .Net 0 07-04-2003 12:10 PM



Advertisments