Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.6-';非类型';测试失败_Python_Python 3.x - Fatal编程技术网

Python 3.6-';非类型';测试失败

Python 3.6-';非类型';测试失败,python,python-3.x,Python,Python 3.x,我正在从sqlite3数据库中读取数据并过滤掉NoneType,因为我只想要而不是None的值。我尝试了建议的两种方法,得到了相同的结果。这让我觉得下面的if语句是正确的,但我遗漏了一些更基本的东西。如有任何建议,我们将不胜感激 从数据库读取 非定型试验 错误 TypeError:int()参数必须是字符串、类似字节的对象或数字,而不是“NoneType” 如果我在我的if语句中专门标记而不是None类型,为什么会出现此错误 正确的方法是什么,例如当值为None时,我可以指定预定义的值 您可以

我正在从
sqlite3
数据库中读取数据并过滤掉
NoneType
,因为我只想要而不是
None
的值。我尝试了建议的两种方法,得到了相同的结果。这让我觉得下面的if语句是正确的,但我遗漏了一些更基本的东西。如有任何建议,我们将不胜感激

从数据库读取 非定型试验 错误 TypeError:int()参数必须是字符串、类似字节的对象或数字,而不是“NoneType”

  • 如果我在我的
    if语句中专门标记
    而不是None
    类型,为什么会出现此错误
  • 正确的方法是什么,例如当值为
    None
    时,我可以指定预定义的值
您可以添加一个额外的测试来检查列表中的第一项是否不是
None
,这是您实际试图转换为整数的内容:

if current_tact is not None and current_tact[0] is not None:
    current_tact = int(current_tact[0])
或者使用
try except
块来避免测试:

try:
    current_tact = int(current_tact[0])
except TypeError:
    current_tact = 60

current\u-tact=[None]
(或包含
None
作为第一个元素的列表/元组)?似乎current\u-tact中不存在任何元素。尝试
print(current\u-tact)
,您会立即看到问题。@hiroprotagent,绝对正确。输出是:
(无,)
谢谢你指引我正确的方向,阿兰菲,这是我这方面的基本错误。
current_tact = int(current_tact[0])
if current_tact is not None and current_tact[0] is not None:
    current_tact = int(current_tact[0])
try:
    current_tact = int(current_tact[0])
except TypeError:
    current_tact = 60