简体   繁体   English

如何解决“'NoneType' 对象不可下标”的问题?

[英]How to fix the problem of "'NoneType' object is not subscriptable."?

I am trying to conditionally select all the cells in the range in excel by python, but this shows every time.我试图通过python有条件地选择excel范围内的所有单元格,但这每次都会显示。 'NoneType' object is not subscriptable Is there a way to fix it? 'NoneType' object is not subscriptable有没有办法修复它?

I have already tried to put a str around ws.cell(...) , but it still does not work.我已经尝试在ws.cell(...)周围放置一个str ,但它仍然不起作用。

target_list = []

for i in range(1,20638):
    for j in range(1,49):
        if ws.cell(row = i, column = j).value[0:4] == "Drug":
            target_list.append(ws.cell(row = i, column = j).value[5:])
        else:
            pass 

I expect to select all the cells that begin with the word "Drug" , but it shows '"'NoneType' object is not subscriptable' every time.'我希望选择所有以单词"Drug"开头的单元格,但它每次都显示'"'NoneType' object is not subscriptable'

Just add a check before that line:只需在该行之前添加一个检查:

target_list = []

for i in range(1,20638):
    for j in range(1,49):
        if (ws.cell(row = i, column = j).value) is None:
            continue
        if ws.cell(row = i, column = j).value[0:4] == "Drug":
            target_list.append(ws.cell(row = i, column = j).value[5:])
        else:
            pass 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 'NoneType' object 不可下标。 错误在哪里? 使用带有管道的 Django 应用程序 - 'NoneType' object is not subscriptable. Where is the error? Used Django App with Pipeline 如何修复“NoneType”object 不是可订阅错误 - How to fix 'NoneType' object is not subscriptable error TypeError: 'NoneType' object is not subscriptable 问题 - TypeError: 'NoneType' object is not subscriptable Problem “ int”对象不可下标。 大熊猫 - 'int' object is not subscriptable. Pandas Web Scraping :- "" TypeError: 'NoneType' 对象不可下标""。 如何解决这个问题? - Web Scraping :- "" TypeError: 'NoneType' object is not subscriptable "". How to fix this issue? 如何解决:'NoneType' object 不可下标 - How to solve: 'NoneType' object is not subscriptable 如何解决 -'NoneType' object 不可订阅 - How to resolve -'NoneType' object is not subscriptable 'int' object 不可下标。 元组错误 - 'int' object is not subscriptable. Tuple error 类型错误:“设置”对象不可下标。 3 个 CSV 文件 - TypeError: 'set' object is not subscriptable. 3 CSV files TypeError: 'type' object 不可下标。 我怎样才能让它从二维数组中删除一个数组? - TypeError: 'type' object is not subscriptable. How can I get this to remove an array from a 2d array?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM