[portland] Need Help With a For Loop

kirby urner kirby.urner at gmail.com
Fri Mar 21 14:46:28 CET 2008


Note:  my recommendation at the last PPUG, among a
smattering of I hoped useful comments, was for Rich
to publish to this list a black box unit test we could
simply cut and paste and help out with the missing part.

def testfuction(td):
    missing part:  what we help with
    includes print statements

testdata = (whatever tuples)
testfunction(testdata)

Printed output:

Plot 1:
   do function A with args a,b,c
   do function B with args d,e,f
   ....
Plot 2:
   do function C with args a,b,c
   do function B with args d,e,f
   ....

I'm hazy on the printed output part, because
I'm still confused about what Rich is squeezing
from his data input sponge -- that's what I have
a hard time abstracting from any recent post.

The printed output of testfunction (presumably
a loop of some kind) should emulate calling
each of those plots, some superimposed on
the same set of axes (that's an important
wrinkle, I get that -- would be easy if each graph
had its own set of axes).

If the output correctly mirrors what's needed to
satisfy the plotting functions, then we have the
basis for a useful/relevant unit test.

I would suggest that the data look deliberately
phony, not deliberately realistic, e.g.

('term1', 'name1', 'a', 'b', 'c', 'xx', 'yy', 'zz') or whatever,
but correctly mirror the underlying input, i.e. the
patterns should be there.  Doesn't have to be a
*lot* of data, maybe 20 tuples?

The key is to use these same strings in the ouput,
so the testfunction (a kind of mapping) can do its
thing.

I don't think this is "busy work" by today's criteria
as a lot of us believe in "writing tests first" e.g. you
make little tests like this as a basis for building
up code, and you keep the tests in the module,
run them again and again, any time you make
changes.

Note that *not* included in the above is any
discussion of nested for loops, as that's all
about implementation (a black box).

We only care about input and output.

Nor is there any discussion of how "I tried this
but got this output instead of that output" i.e.
there's no debugging of any attempted solution.

As assistants to Rich, our job would be to
generate his output exactly (to the letter), from
his input (cutting and pasting a valid data
structure).  If that is successful, then Rich
would have his solution -- provided the input
and output were crafted appropriately (which
is the challenge at this point).

Yes. he's done something *like* this a number
of times, but not quite simply enough I don't think,
when it comes to the printed output especially.

Kirby

On Fri, Mar 21, 2008 at 6:17 AM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
> On Thu, 20 Mar 2008, mark gross wrote:
>
>  > perhaps I'm missing something but I'm not seeing where the i variable
>  > is used in the loop block.
>
>  Mark,
>
>    I went off in the wrong direction with this function from the start, and I
>  need to re-write it using list comprehension.
>
>    What I need to do is cycle through different items in the tuples in a
>  nested fashion. That is:
>
>    For each level-1 name in the list of tuples:
>      For each level-2 name in each level-1 name:
>        For each level-3 name in each level-2 name:
>         For each level-4 name in each level-3 name3:
>           Call the appropriate plotting function based on curve shape.
>
>    At my level of python experience this is proving to be a major challenge
>  that has taken my attention for well too much time. For those of you with
>  more experience the algorithm implementation is probably simple and obvious.
>
>
>  Rich
>
>  --
>  Richard B. Shepard, Ph.D.               |  Integrity            Credibility
>  Applied Ecosystem Services, Inc.        |            Innovation
>  <http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax: 503-667-8863
>  _______________________________________________
>
>
> Portland mailing list
>  Portland at python.org
>  http://mail.python.org/mailman/listinfo/portland
>


More information about the Portland mailing list