Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.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 仅当对象不是“时,如何重新跳闸”;“无类型”;_Python - Fatal编程技术网

Python 仅当对象不是“时,如何重新跳闸”;“无类型”;

Python 仅当对象不是“时,如何重新跳闸”;“无类型”;,python,Python,findloc是我创建的另一个子例程,当调用parse时,有时返回None,有时返回值,当尝试rstrip时,我得到以下错误?如何仅在对象为非“nonetype”时使用rstrip,或者请建议任何其他方法 build_loc=parse(findloc(targetmeta_cid).strip()) Target_list.append(build_loc.rstrip('\r\n')) 错误 或 更简洁的方法可能是确保parse不会返回None 或 更简洁的方法可能是确

findloc是我创建的另一个子例程,当调用parse时,有时返回None,有时返回值,当尝试rstrip时,我得到以下错误?如何仅在对象为非“nonetype”时使用rstrip,或者请建议任何其他方法

    build_loc=parse(findloc(targetmeta_cid).strip())
    Target_list.append(build_loc.rstrip('\r\n'))
错误


更简洁的方法可能是确保
parse
不会返回
None


更简洁的方法可能是确保
parse
不会返回
None

你可以这样做

if build_loc is not None:
    Target_list.append(build_loc.rstrip('\r\n'))
为了让它工作。希望这有帮助:)

你可以这样做

if build_loc is not None:
    Target_list.append(build_loc.rstrip('\r\n'))

为了让它工作。希望这有帮助:)

如果
parse
返回None,这意味着什么?这是一个错误吗?该怎么办?您需要先回答这个问题,然后才能决定如何正确处理该案例。如果
parse
返回None,这意味着什么?这是一个错误吗?该怎么办?你需要先回答这个问题,然后才能决定如何妥善处理这个案件。
build_loc = parse(findloc(targetmeta_cid).strip()) or ''
if build_loc is not None:
    Target_list.append(build_loc.rstrip('\r\n'))