util.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:skutil 作者: tgsmith61591 项目源码 文件源码
def is_integer(x):
    """Determine whether some object ``x`` is an
    integer type (int, long, etc).

    Parameters
    ----------

    x : object
        The item to assess


    Returns
    -------

    bool
        True if ``x`` is an integer type
    """
    try:
        python_major_version = sys.version_info.major
        assert(python_major_version == 2 or python_major_version == 3)
        if python_major_version == 2:
            return (not isinstance(x, (bool, np.bool))) and \
                isinstance(x, (numbers.Integral, int, long, np.int, np.long))
        elif python_major_version == 3:
            return (not isinstance(x, (bool, np.bool))) and \
                isinstance(x, (numbers.Integral, int, np.int, np.long))
    except AssertionError:
        _, _, tb = sys.exc_info()
        traceback.print_tb(tb)  # Fixed format
        tb_info = traceback.extract_tb(tb)
        filename, line, func, text = tb_info[-1]

        print('An error occurred on line {} in statement {}'.format(line, text))
        exit(1)
    return _is_integer(x)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号