这两种方法有什么区别? (又名,为什么其中一个不起作用?) [英] what's the difference between these two methods? (aka, why doesn't one of them work?)

查看:81
本文介绍了这两种方法有什么区别? (又名,为什么其中一个不起作用?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释为什么这个方法的第一个版本有效,

但第二个版本不是吗?所有我改变了(我认为)是如何嵌套

信息。我得到的错误是在第二个例子中对

xrc.XRCCTRL的调用不起作用。它没有得到适当的小部件,而是返回无。这是

嵌套的结果,或者也许是for循环?


谢谢。

def OnSaveRecord(自我,事件) ):

textfield_values = []

for self.notebook.GetCurrentPage()中的标签.GetChildren():

表格中的self。 get_textfield_ids():

table_values = []

表格中的textfield_id:

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'',''的薪水'',''labBuilding'',''labRoom'',

''labPhone''),

(''localAddress'',''foreig nAddress'',''emailAddress'',

''homePhone'',

''foreignPhone'',''cellPhone''),(''university1' ',

''yearStart1'',

''yearEnd1'',''degree1'',''university2'',''yearStart2'',

''yearEnd2'',

''degree2'',''university3'',''yearStart3'',''yearEnd3'',

''degree3'',

''university4'','yearStart4'',''yearEnd4'',''degree4''),

( ''notes''))


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


def OnSaveRecord(自我,事件):

textfield_values = []

对于self.get上的选项卡.GetCurrentPage()。GetChildren():

for self.get_textfield_ids()中的textfield_id:

textfield_values.append(xrc.XRCCTRL(tab,

textfield_id)。GetValue())

self.save_to_database(textfi eld_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'',''y earEnd4'',''degree4'',

''notes'')


Traceback(最近一次调用最后一次):

文件" C:\Python25 \ _myscripts \ labdb\dbapp.py",第91行,在OnSaveRecord中

table_values.append(xrc.XRCCTRL(tab,textfield_id).GetValue ())

AttributeError:''NoneType''对象没有属性''GetValue''

解决方案

< blockquote>

JohnJSal写道:


有人可以向我解释为什么这个方法的第一个版本有效,

但第二个不是吗?



对不起,这是第一个不起作用的。第二个是。


On Thu,2006-11-02 at 12:28 -0800,JohnJSal写道:


有人可以向我解释为什么这个方法的第一个版本有效,

但第二个版本不是吗?所有我改变了(我认为)是如何嵌套

信息。我得到的错误是在第二个例子中对

xrc.XRCCTRL的调用不起作用。它没有得到适当的小部件,而是返回无。这是

嵌套的结果,还是for循环?

[...]

Traceback(最近一次调用最后一次) :

文件" C:\Python25 \ _myscripts \ labdb \dbapp.py",第91行,在OnSaveRecord中

table_values.append(xrc.XRCCTRL (tab,textfield_id).GetValue())

AttributeError:''NoneType''对象没有属性''GetValue''



您可能会发现在

导致异常的行之前检查(例如打印)textfield_id很有帮助。


-Carsten


JohnJSal写道:


有人可以向我解释为什么这个方法的第一个版本有效,

但是第二个不是吗?所有我改变了(我认为)是如何嵌套

信息。我得到的错误是在第二个例子中对

xrc.XRCCTRL的调用不起作用。它没有得到适当的小部件,而是返回无。这是

嵌套的结果,或者也许是for循环?


谢谢。


def OnSaveRecord (自我,事件):

textfield_values = []

for self.notebook.GetCurrentPage()中的标签.GetChildren():

for self.get_textfield_ids()中的表:

table_values = []

表格中的textfield_id:



Put在一个

打印textfield_id


这里。在异常发生之前你会看到'n''


,因为......


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



....以上不是1元组,但是普通的字符串。你忘了

尾随逗号:


(''notes'',)


彼得


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

解决方案


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.


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


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


这篇关于这两种方法有什么区别? (又名,为什么其中一个不起作用?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆