473,326 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

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:
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'))

-----------------------------------------

def OnSaveRecord(self, event):
textfield_values = []
for tab in self.notebook.GetCurrentPage().GetChildren():
for textfield_id in self.get_textfield_ids():
textfield_values.append(xrc.XRCCTRL(tab,
textfield_id).GetValue())
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')

Traceback (most recent call last):
File "C:\Python25\myscripts\labdb\dbapp.py", line 91, in OnSaveRecord
table_values.append(xrc.XRCCTRL(tab, textfield_id).GetValue())
AttributeError: 'NoneType' object has no attribute 'GetValue'

Nov 2 '06 #1
13 1350

JohnJSal wrote:
Can someone explain to me why the first version of this method works,
but the second one doesn't?
Sorry, it's the first one that doesn't work. The second one does.

Nov 2 '06 #2
On Thu, 2006-11-02 at 12:28 -0800, 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?
[...]
Traceback (most recent call last):
File "C:\Python25\myscripts\labdb\dbapp.py", line 91, in OnSaveRecord
table_values.append(xrc.XRCCTRL(tab, textfield_id).GetValue())
AttributeError: 'NoneType' object has no attribute 'GetValue'
You might find it helpful to inspect (e.g. print) textfield_id before
the line that causes the exception.

-Carsten
Nov 2 '06 #3
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

Nov 2 '06 #4

Peter Otten wrote:

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

('notes',)
Right you are! Now it works! :)

Thanks!

Nov 2 '06 #5
JohnJSal wrote:
Peter Otten wrote:

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

('notes',)

Right you are! Now it works! :)

Thanks!
Oh great, now I've moved on to another issue. It seems that the list
appending isn't working right. All that gets added to a list is the
last value, not everything. Am I doing something wrong with the append
method?

Nov 2 '06 #6

JohnJSal wrote:
JohnJSal wrote:
Peter Otten wrote:

...the above is not a 1-tuple, but an ordinary string. You forgot the
trailing comma:
>
('notes',)
Right you are! Now it works! :)

Thanks!

Oh great, now I've moved on to another issue. It seems that the list
appending isn't working right. All that gets added to a list is the
last value, not everything. Am I doing something wrong with the append
method?
Ah, got it! I was reinitializing the table_values list in the wrong
place

Nov 2 '06 #7

JohnJSal wrote:
JohnJSal wrote:
Peter Otten wrote:

...the above is not a 1-tuple, but an ordinary string. You forgot the
trailing comma:
>
('notes',)
Right you are! Now it works! :)

Thanks!

Oh great, now I've moved on to another issue. It seems that the list
appending isn't working right. All that gets added to a list is the
last value, not everything. Am I doing something wrong with the append
method?
Well, append method is for appending a value to a list. A single value.
You can use extend method (iirc) to extend a list with another list.

Nov 2 '06 #8
On Thu, 2006-11-02 at 13:14 -0800, JohnJSal wrote:
JohnJSal wrote:
JohnJSal wrote:
Peter Otten wrote:
>
>
...the above is not a 1-tuple, but an ordinary string. You forgot the
trailing comma:

('notes',)
>
Right you are! Now it works! :)
>
Thanks!
Oh great, now I've moved on to another issue. It seems that the list
appending isn't working right. All that gets added to a list is the
last value, not everything. Am I doing something wrong with the append
method?

Ah, got it! I was reinitializing the table_values list in the wrong
place
The fact that you were able to answer your own question only a few
minutes later indicates to me that you should set your "I give up and
ask the list" threshold a tad higher.

-Carsten
Nov 2 '06 #9
Carsten Haese wrote:
The fact that you were able to answer your own question only a few
minutes later indicates to me that you should set your "I give up and
ask the list" threshold a tad higher.
That's a perfectly valid comment, but in this case just not applicable.
I spent a lot of time working through my original question before
posting, but I just couldn't get it. It's not like I didn't try
anything at all before posting the follow-up, either. I just happened
to notice one more thing after posting.

Nov 2 '06 #10
JohnJSal wrote:
That's a perfectly valid comment, but in this case just not applicable.
I spent a lot of time working through my original question before
posting, but I just couldn't get it.
how do you fit "a lot of time" into 18 minutes?

</F>

Nov 2 '06 #11
Fredrik Lundh wrote:
JohnJSal wrote:
>That's a perfectly valid comment, but in this case just not applicable.
I spent a lot of time working through my original question before
posting, but I just couldn't get it.

how do you fit "a lot of time" into 18 minutes?

</F>
Hmmm, I had tried to cancel sending that post but I guess it didn't
work. As I was sending it, I said to myself, "well, maybe I didn't spend
enough time before asking."

But I guess rather than "a lot of time", I'm thinking I tried "a lot of
things," or at least all I could think of.
Nov 3 '06 #12
John Salerno wrote:
Fredrik Lundh wrote:
>>JohnJSal wrote:

>>>That's a perfectly valid comment, but in this case just not applicable.
I spent a lot of time working through my original question before
posting, but I just couldn't get it.

how do you fit "a lot of time" into 18 minutes?

</F>

Hmmm, I had tried to cancel sending that post but I guess it didn't
work. As I was sending it, I said to myself, "well, maybe I didn't spend
enough time before asking."

But I guess rather than "a lot of time", I'm thinking I tried "a lot of
things," or at least all I could think of.
Don't worry. It's sometimes difficult for the effbot to remember we
aren't all as fearsomely intelligent as it is. I think it does a
remarkably complete emulation of a human being:

http://www.flickr.com/photos/30842681@N00/152495923/

For what it's worth it's also amazingly helpful if you can ignore to
sometimes acerbic wit.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Nov 3 '06 #13
Steve Holden wrote:
Don't worry. It's sometimes difficult for the effbot to remember we
aren't all as fearsomely intelligent as it is. I think it does a
remarkably complete emulation of a human being:

http://www.flickr.com/photos/30842681@N00/152495923/

For what it's worth it's also amazingly helpful if you can ignore to
sometimes acerbic wit.

regards
Steve
Heh heh. Things wouldn't be the same without him...I mean "it". :)
Nov 4 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
13
by: gtux | last post by:
Hi everybody: I'm new in Javascript, I found some code and there is this: var fruit = { 'apple' : { 'weight' : 10, 'cost' : 9}, 'peach' : { 'weight' : 19, 'cost' : 10} }
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
18
by: cj | last post by:
members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe. I'm under the impression before you can use a class you have to make an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.