如何解决附加返回的非节距
我正在运行一个脚本来将 Spotify 专辑 ID(一次 20 个)发送到 Spotify API,并将每个专辑 ID 中的曲目计数保存到一个列表中,然后在保存到 .csv 之前将其插入到现有数据框中文件。
该文件相当大(100 万行以上),其中大约 900,000 行,我没有遇到任何问题。但是,我最终遇到了 TypeError: "NoneType" object is not subscriptable
常见的问题似乎是 append 函数的使用不正确,但根据我在这里的理解,我以正确的方式使用它。我也不明白为什么该函数在崩溃之前运行了 45000 多次迭代。
我的代码是:
length = len(series)
counter = length // 20
remainder = length % 20
list = [''] * 20
finalList = [''] * remainder
i = 0
x = 0
y = 0
trackListCount = 0
output = []
while i < counter:
j = 0
while j < 20:
list[j] = series[x]
j += 1
x += 1
album1 = sp.albums(list)
j = 0
while j < 20:
output.append(album1["albums"][j]["total_tracks"])
print(album1["albums"][j]["name"])
j += 1
i += 1
print(str(i) + " out of " + str(counter + 1))
if remainder != 0:
while y < remainder:
finalList[y] = series[x]
x += 1
y += 1
album2 = sp.albums(finalList)
y = 0
while y < remainder:
output.append(album2["albums"][y]["total_tracks"])
y += 1
问题出现在第二个while循环中的行上:
output.append(album1["albums"][j]["total_tracks"])
正如我所说,对于 90% 的文件,脚本运行良好,输出仍然是一个列表,直到突然没有
任何帮助将不胜感激
编辑:我忘了提到我在此处使用 Spotipy 库来处理我的请求:https://spotipy.readthedocs.io/en/2.18.0/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。