what's the difference between these two methods? (aka, why doesn't one of them work?)

Peter Otten __peter__ at web.de
Thu Nov 2 15:44:06 EST 2006


JohnJSal wrote:

> Can someone explain to me why the first version of this method works,
> but the second one doesn't? All I've changed (I think) is how the
> information is nested. The error I'm getting is that the call to
> xrc.XRCCTRL is not working in the second example. Instead of getting
> the appropriate widget, it's returning None. Is this a result of the
> nesting, or the for loops perhaps?
> 
> Thanks.
> 
> 
>     def OnSaveRecord(self, event):
>         textfield_values = []
>         for tab in self.notebook.GetCurrentPage().GetChildren():
>             for table in self.get_textfield_ids():
>                 table_values = []
>                 for textfield_id in table:
Put in a 
                      print textfield_id

here. You'll see an 'n'

before the exception occurs, because...

>                     table_values.append(xrc.XRCCTRL(tab,
> textfield_id).GetValue())
>                 textfield_values.append(table_values)
>         self.save_to_database(textfield_values)
> 
>     def get_textfield_ids(self):
>         return (('firstName', 'middleName', 'lastName', 'birthMonth',
>                 'birthDay', 'birthYear', 'country', 'state', 'city'),
>                 ('jobTitle', 'salary', 'labBuilding', 'labRoom',
> 'labPhone'),
>                 ('localAddress', 'foreignAddress', 'emailAddress',
> 'homePhone',
>                 'foreignPhone', 'cellPhone'), ('university1',
> 'yearStart1',
>                 'yearEnd1', 'degree1', 'university2', 'yearStart2',
> 'yearEnd2',
>                 'degree2', 'university3', 'yearStart3', 'yearEnd3',
> 'degree3',
>                 'university4', 'yearStart4', 'yearEnd4', 'degree4'),
> ('notes'))

...the above is not a 1-tuple, but an ordinary string. You forgot the
trailing comma: 

('notes',)

Peter




More information about the Python-list mailing list