这是我的 python 脚本报告的错误:
TypeError Traceback (most recent call last)
/home/jhourani/openbel-contributions/resource_generator/change_log.py in <module>()
37 for k, v in namespaces.items():
38 #ipdb.set_trace()
---> 39 if v[0]:
40 v[1].append(token)
41
TypeError: 'bool' object is not subscriptable
好的,我猜这一切都很好。但是当我进一步检查这个元素时ipdb
,结果如下:
>>> v
(False, [])
>>> type(v)
<class 'tuple'>
>>> v[0]
False
>>> if v[0]:
... print('true')
... else:
... print('false')
...
false
>>>
条件测试适用于ipdb
,但是当我运行脚本时,解释器似乎将其v
视为布尔值,而不是当然是可下标的元组。1. 为什么?2.为什么两者有区别?
这是我编写的代码块:
old_entrez = []
old_hgnc = []
old_mgi = []
old_rgd = []
old_sp = []
old_affy = []
# iterate over the urls to the .belns files
for url in parser.parse():
namespaces = { 'entrez' : (False, old_entrez), 'hgnc' : (False, old_hgnc),
'mgi' : (False, old_mgi), 'rgd' : (False, old_rgd),
'swissprot' : (False, old_sp), 'affy' : (False, old_affy) }
open_url = urllib.request.urlopen(url)
for ns in namespaces.keys():
if ns in open_url.url:
namespaces[ns] = True
marker = False
for u in open_url:
# skip all lines from [Values] up
if '[Values]' in str(u):
marker = True
continue
if marker is False:
continue
# we are into namespace pairs with '|' delimiter
tokenized = str(u).split('|')
token = tokenized[0]
for k, v in namespaces.items():
ipdb.set_trace()
if v[0]:
v[1].append(token)