在python我想要返回none而不是空字符串

时间:2017-07-14 15:07:46

标签: python-2.7

我想要返回任何但是这给了我一个错误 我不想返回空字符串

def read_line2(self, timeout=None):  ## Read Radio2 Serial line
        try:
            return self._rq2.get(block=timeout, timeout=timeout)
        except Empty:
            return ''

1 个答案:

答案 0 :(得分:0)

在python中返回None,只需return None

def returns_none():
    return None


x = returns_none()
assert x is None

我认为您的问题与except Empty:有关。是否为您已定义的自定义异常,因为它不是内置的python。