![](/img/trans.png)
[英]Python - TypeError: object of type 'NoneType' has no len()
[英]TypeError: object of type 'NoneType' has no len() python fix this?
我如何解決這個問題........完整的代碼在下面,它應該搜索表單的所有成員並最終將它們打印並保存到一個csv文件中
import csv
import time
def main():
myList = [ ]
myList = read_csv()
##myList = showList(myList)
searchList = searchQueryForm(myList)
if searchList:
showList(searchList)
else:
print("I have nothing to print")
if len(searchList) == 0:
TypeError: object of type 'NoneType' has no len()
不知道這意味着什么,任何人都可以解決此問題。
盡快
這意味着您的searchList為空。 函數searchQueryForm可能導致空對象。 您可以嘗試打印並查看
這意味着您的searchQueryForm
函數返回None
。 您可以更改它以返回一個空列表( []
)(如果更合適),或者更改條件以檢查結果,如下所示:
if not searchList:
print("I have nothing to print")
else:
showList(searchList)
這將檢查searchList
變量是否為None
或為空( 說明 )。
如果取得結果是預期的實現方式,那么我建議翻轉條件。 正面條件通常在閱讀代碼時更容易理解:
if searchList:
showList(searchList)
else:
print("I have nothing to print")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.