[Tutor] Dynamic-ish naming of variables?

Liam Clarke cyresse at gmail.com
Mon Nov 22 10:59:11 CET 2004


Hi Danny,

It has been said that Kiwis (the people, not bird or Americanised name
of a fruit) are a fairly unemotional & laidback bunch of people. Well,
not this misnamed fruit (which was originally called a chinese
gooseberry).

I just did an impression of an overexcitable Mediterranean soccer fan
watching his 99th ranked in the world team come back to win in the
penalty shoot out against Brazil.

I tried the code as follows - 

def on_PastReportButton_mouseClick(self, event):
        nameList=['CheckBox1']
        print "This won't be doing jack until you've run the first option."
        self.testWindow=model.childWindow(self, test.testDict)

        for name in nameList:
            if self.testWindow.components[name].checked: print "It vorked"

and I got - 

This won't be doing jack until you've run the first option.
It vorked

So a thousand thanks Danny, my brain was going seriously curly trying
to figure that one out.

Regards,

Liam Clarke




On Mon, 22 Nov 2004 00:35:15 -0800 (PST), Danny Yoo
<dyoo at hkn.eecs.berkeley.edu> wrote:
> 
> 
> On Mon, 22 Nov 2004, Liam Clarke wrote:
> 
> > Python checks values assigned by the following -
> >
> > if self.components.LiamClarkeCheck.checked=True ....
> 
> Hi Liam,
> 
> Hmmm!  I haven't played with PythonCard that much yet.  According to the
> documentation on:
> 
>  http://pythoncard.sourceforge.net/framework/general_concepts_and_limitations.html
> 
> "components" is a dictionary-like object, with extra syntactic sugar so
> that we can use dot notation.  That means that, hopefully, we're pretty
> much home free, because it's fairly easy to do dynamic inserts into a
> dictionary without much magic.
> 
> I believe the 'components' attribute is an instance of the 'WidgetDict'
> class, from looking at the code of PythonCard's data model:
> 
> http://cvs.sourceforge.net/viewcvs.py/pythoncard/PythonCard/model.py?rev=1.190&view=auto
> 
> 
> > Ideally it would iterate over a list, something along these pseudo-lines
> > for name in nameList:
> >     if self.components.%sCheck.checked=True % name
> >     teamDict[name]=self.components.%sChoice.field % name
> 
> 
> You should actually be able to say something like:
> 
> ###
> for name in nameList:
>     if self.components[name].checked = True:
>         teamDict[name] = self.components[name].checked
> ###
> 
> I have not tested this yet though.  I'm going to regret saying that,
> aren't I?  *grin* I just don't have access to wxPython at the moment.
> 
> If you have more questions, please feel free to ask!
> 
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.


More information about the Tutor mailing list