Your first problem, you're reusing 'p' in two contexts that appear to be
conflicting.
Tom,
That's because what I posted was one of my groping attempts to get the
right combination of variables in the right place.
If I'm guessing correctly, the setup is thus:
. subPols is a list (or tuple, even?) of tuples
. Each entry of subPols is (masterPolicy, subPolicy)
. As you go through the list of subPols, you want to only inspect the
ones that have a matching masterPolicy.
Is that accurate?
Almost. subPols is a list of tuples retrieved from the database table.
Each entry of subPols is (subpol_name, pol_name) -- but this is minor.
The pol_name are the twigs on a wx.TreeCtrl(), and the subpol_names are
the leaves on each twig. Not all policies will have subpolicies.
As I go through the list of subPols tuples, I want to append each
subpol_name to the matching pol_name.
If so, try this, names changed to prevent ambiguity
for item in self.appData.polNat:
ngc = self.polTree.AppendItem(self.natID, item[0])
policy = self.polTree.GetItemText(ngc)
print "This is the policy: ", policy
for subpolicy in self.appData.subPols:
print "This should be the list of subpolicies: ",
if subpolicy[0] == policy \
print subPolicy[1],
print '\n'
The print statements are strictly for debugging, and I'll change the index
of subpolicy to [1], then give it a try a bit later today (after the house
maintenance and yard work are finished).
"List comprehensions" would also make this fairly straight-forward, once
you get your head around them:
for item in self.appData.polNat:
ngc = self.polTree.AppendItem(self.natID, item[0])
policy = self.polTree.GetItemText(ngc)
print "This is the policy: ", policy
subpolicies = \
[sp[1] for sp in self.appData.subPols if sp[0]==policy]
This makes sense as I read it. I don't yet have enough experience to write
it myself.
What that is doing is going through the list of subPols, and each one
that matches gets tossed into another list.
Instead, I'll append each subPol to the matching Pol.
Now from a software engineering perspective, I might suggest using
objects rather than tuples, so the fields can be named:
class Subpolicy:
def __init__(self, parent, name):
self.parent = parent
self.name = name
...and then throw those into your subpols list, but that's another
discussion for another forum.
All data live in database tables. What I'm working on is loading stored
values into the proper widgets when a model database is opened.
Many thanks. I'll report back, probably tomorrow some time.
Rich
···
On Sat, 16 Dec 2006, Tom Plunket wrote:
--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc.(TM) | Accelerator
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863