Python 2.6中无类型问题
我正在编写一个脚本,从数据库中获取一些值,但有时该值可能为零,但当我将其分配给变量并尝试进行比较时,会出现以下错误:Python 2.6中无类型问题,python,Python,我正在编写一个脚本,从数据库中获取一些值,但有时该值可能为零,但当我将其分配给变量并尝试进行比较时,会出现以下错误: TypeError: 'NoneType' object is unsubscriptable 我已经试过了: if sgSlate[ 'sg_client_2' ][ 'name' ] != None: self.ui.brandComboBox_2.setEditText( sgSlate[ 'sg_client_2' ]['name' ] ) if not is
TypeError: 'NoneType' object is unsubscriptable
我已经试过了:
if sgSlate[ 'sg_client_2' ][ 'name' ] != None:
self.ui.brandComboBox_2.setEditText( sgSlate[ 'sg_client_2' ]['name' ] )
if not isinstanceof( sgSlate[ 'sg_client_2' ][ 'name' ], None ) != "":
self.ui.brandComboBox_2.setEditText( sgSlate[ 'sg_client_2' ]['name' ] )
if sgSlate[ 'sg_client_2' ][ 'name' ] is not None:
self.ui.brandComboBox_2.setEditText( sgSlate[ 'sg_client_2' ]['name' ] )
if type( sgSlate[ 'sg_client_2' ][ 'name' ]) is not type(None):
self.ui.brandComboBox_2.setEditText( sgSlate[ 'sg_client_2' ]['name' ] )
他们都没有成功
请提前感谢。当您尝试对
无
变量执行[]
操作时,会出现取消订阅错误。因此,在本例中,最有可能的是sgSlate['sg\u client\u 2']
值None
,而不是sgSlate['sg\u client\u 2']['name']
本身。好的,就是这样。在所有时区,直到4月2日才开始投票,我已经厌倦了这些愚蠢的独角兽:)