- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个产生错误的 python 程序:
def update_ranges(phonemelist) :
""" updating the rows and columns of the list of input phonemes"""
# make a copy of the list as we're going to modify it (optional)
phonlist = phonemelist[:]
# we don't need the row titles, they just complicate things
rowtitles, phonlist = zip(*phonlist)
rows = len(phonlist)
columns = range(len(phonlist[0]))
# for each row except the last
for i in xrange(rows - 1):
# update it by going down all the rows below it
for k in xrange(i+1, rows):
# for both columns
for j in columns:
update(phonlist, i, j, k, j)
# put the row titles back in (optional)
phonlist = zip(rowtitles, phonlist)
return phonlist
def update(phonlist, curr_row, curr_col, next_row, next_col) :
""" applying co-articulation rules for comparing the ranges """
curr_low, curr_high = phonlist[curr_row][curr_col]
next_low, next_high = phonlist[next_row][next_col]
# Rule 1: when one of the ranges is (-1,-1)
# replace the current range if it's (-1, -1) as its empty
if (curr_low, curr_high) == (-1, -1) :
phonlist[curr_row][curr_col] = next_low, next_high
return
# do nothing if the next range is (-1,-1)
if (next_low, next_high) == (-1, -1) :
return
# Rule 2: when ranges don't overlap
# replace the lowest value of current range when the next range is lower than the current range
elif curr_low > next_high :
phonlist[curr_row][curr_col] = curr_low, curr_low
return
# replace the highest values of current range when the next range is higher than the current range
elif next_low > curr_high :
phonlist[curr_row][curr_col] = curr_high, curr_high
return
# Rule 3: when ranges completely overlap
elif curr_low <= next_low and next_high <= curr_high or curr_low >= next_low and next_high >= curr_high :
# replace the values of the next range when the next range completely lies in the current range
if curr_high - curr_low > next_high - next_low :
phonlist[curr_row][curr_col] = next_low, next_high
return
# replace the values of the current range when the current range completely lies in the next range
else :
phonlist[curr_row][curr_col] = curr_low, curr_high
return
# Rule 4: when the ranges partially overlap
else :
# replace the values that is common to both ranges when next range is further ahead of the current
if curr_low < next_low and curr_high < next_high :
phonlist[curr_row][curr_col] = next_low, curr_high
return
# replace the values that is common to both ranges when current range is further ahead of the next
else :
phonlist[curr_row][curr_col] = curr_low, next_high
return
错误:
File "coarticulation.py", line 217, in update
next_low, next_high = phonlist[next_row][next_col]
TypeError: 'NoneType' object is unsubscriptable
错误是什么意思,我该如何解决?
最佳答案
这是当您尝试从 None
值(Python 的 null
等价物)访问下标(索引)值时 Python 返回的错误:
>>> a = None
>>> a[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not subscriptable
关于python - 类型错误 : 'NoneType' object is unsubscriptable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7034024/
最后一行给我一个错误 check_alert_json = [ ] for k in check_job_stats_json.keys(): if : check_aler
我是按照《Django for beginners》这本书学习Django的,有个奇怪的问题。下面的代码片段确实有效,但 Pylint 一直向我显示错误,我知道错误发生了。但是作者什么也没做。请问有人
我正在尝试编写一个函数来返回任何小于 1000 的数字的字符串。 每次我在交互式提示符下运行代码时,它似乎都可以正常工作,但是当我尝试导入 wordify 并使用高于 20 的测试编号运行它时,它会失
我从代码中收到一条错误消息,其中显示 TypeError: 'int' object is unsubscriptable。经过一番研究,我明白了它的意思,但我不明白为什么会出现问题。 我将问题范围缩
当我运行这段代码时,Python 解释器出现了一个奇怪的错误: def make_map(): map = [[Tile(0, 0) for col in range(MAP_WIDTH)]
我正在模拟循环算法,下面列出的代码给我错误 RR.Przesuniecie[Oczekujace_procesy] TypeError: 'instancemethod' object is unsu
使用 Python 运行此代码时出现此错误: TypeError: "NoneType" object is unsubscriptable". 代码: number = 0 with open('p
我有一个产生错误的 python 程序: def update_ranges(phonemelist) : """ updating the rows and columns of the l
在 python 中我得到这个错误: TypeError: 'int' object is unsubscriptable 这发生在行: sectorcalc[i][2]= ((today[2]/ye
我是 python 的新手,不太了解我的问题,非常感谢您的帮助。无论如何,这是编码行。 def Banker(warrior): gold = open(chairs[warrior-1],
我正在尝试扫描我的服务器是否存在漏洞,我正在使用 Wapiti 来执行此操作。奇怪的是,当我运行它时,我收到此错误。怎么了? root@server [~/wapiti-2.3.0/bin]# pyt
我正在尝试从 openerp 中具有此函数的类中读取另一个类的对象内的字段: def desc_cert(self, cr, uid, ids, field_name, field_args, con
我编译了这个程序,它从细胞图像中提取特征,并在 python-3.5 上使用 randomforestclassifier 判断它是否癌变。我是在 Windows 8.1 上制作的,它运行良好。但它不
我在执行以下脚本时遇到错误“int object is unsubscriptable”: element.reduceByKey( lambda x , y : x[1]+y[1]) with el
我只是将以下“最小”重现案例放在一起(最小引号是因为我想确保 pylint 没有抛出其他错误、警告、提示或建议 - 这意味着有一些样板): pylint_error.py : """ Docstrin
我有以下代码: from random import randint,choice add=lambda x:lambda y:x+y sub=lambda x:lambda y:x-y mul=la
我昨晚更新了 GoogleAppEngineLauncher,现在我收到了这个错误 Python 2.6.1: /usr/bin/python Tue Nov 8 09:25:13 2011 A
sqlite3 lib 对象 connect 上的 fetchone() 函数出现问题: 我执行的查询可能并不总是返回值; 检查它是否有返回值; 如果它返回一个值,我使用 fetchone()[0]
我想使用 Python 中的 Azure Functions 写入 Azure Blob 存储。 我正在使用 Azure Functions 的输出 Blob 存储绑定(bind)。 我的函数.jso
我想使用 Python 中的 Azure Functions 写入 Azure Blob 存储。 我正在使用 Azure Functions 的输出 Blob 存储绑定(bind)。 我的函数.jso
我是一名优秀的程序员,十分优秀!