当前位置: 首页>>代码示例>>Python>>正文


Python unicodedata.numeric方法代码示例

本文整理汇总了Python中unicodedata.numeric方法的典型用法代码示例。如果您正苦于以下问题:Python unicodedata.numeric方法的具体用法?Python unicodedata.numeric怎么用?Python unicodedata.numeric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unicodedata的用法示例。


在下文中一共展示了unicodedata.numeric方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ipy2_gh357

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def test_ipy2_gh357(self):
        """https://github.com/IronLanguages/ironpython2/issues/357"""

        import unicodedata

        if is_cli:
            self.assertEqual(unicodedata.name(u'\u4e2d'), '<CJK IDEOGRAPH, FIRST>..<CJK IDEOGRAPH, LAST>')
        else:
            self.assertEqual(unicodedata.name(u'\u4e2d'), 'CJK UNIFIED IDEOGRAPH-4E2D')

        self.assertRaises(ValueError, unicodedata.decimal, u'\u4e2d')
        self.assertEqual(unicodedata.decimal(u'\u4e2d', 0), 0)
        self.assertRaises(ValueError, unicodedata.digit, u'\u4e2d')
        self.assertEqual(unicodedata.digit(u'\u4e2d', 0), 0)
        self.assertRaises(ValueError, unicodedata.numeric, u'\u4e2d')
        self.assertEqual(unicodedata.numeric(u'\u4e2d', 0), 0)
        self.assertEqual(unicodedata.category(u'\u4e2d'), 'Lo')
        self.assertEqual(unicodedata.bidirectional(u'\u4e2d'), 'L')
        self.assertEqual(unicodedata.combining(u'\u4e2d'), 0)
        self.assertEqual(unicodedata.east_asian_width(u'\u4e2d'), 'W')
        self.assertEqual(unicodedata.mirrored(u'\u4e2d'), 0)
        self.assertEqual(unicodedata.decomposition(u'\u4e2d'), '') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_regressions.py

示例2: convert_floats

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def convert_floats(data, integers=None):
    """
    Convert all numeric values in dictionary to float type.
    """
    integers = integers or []
    delete_keys = []
    for key, value in data.iteritems():
        try:
            if isinstance(value, datetime.datetime):
                continue
            if is_number(value):
                if key in integers:
                    data[key] = int(value)
                else:
                    data[key] = float(value)
            if math.isnan(data[key]):
                delete_keys.append(key)
        except:
            pass

    for key in delete_keys:
        del data[key]

    return data 
开发者ID:daq-tools,项目名称:kotori,代码行数:26,代码来源:util.py

示例3: is_number

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def is_number(s):
    """
    Check string for being a numeric value.
    http://pythoncentral.io/how-to-check-if-a-string-is-a-number-in-python-including-unicode/
    """
    try:
        float(s)
        return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass

    return False 
开发者ID:daq-tools,项目名称:kotori,代码行数:21,代码来源:util.py

示例4: __IsNumber

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def __IsNumber(self, input_data):
        result = False
        try:
            float(input_data)
            result = True
        except ValueError:
            pass

        if result:
            temp = float(input_data)
            if np.isnan(temp):
                return False
            if np.isinf(temp):
                return False

        if not result:
            try:
                import unicodedata
                unicodedata.numeric(input_data)
                result = True
            except (TypeError, ValueError):
                pass

        return result 
开发者ID:salan668,项目名称:FAE,代码行数:26,代码来源:DataContainer.py

示例5: is_number

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def is_number(s):
    """Determines if the input is numeric

    Args:
        s: The value to check.
    Returns:
        bool: ``True`` if the input is numeric, ``False`` otherwise.

    """
    try:
        float(s)
        return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass

    return False
#---------------------------------------------------------------------- 
开发者ID:Esri,项目名称:ArcREST,代码行数:26,代码来源:common.py

示例6: is_number

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def is_number(s):
    result = False
    try:
        float(s)
        result = True
    except ValueError:
        pass

    if not result:
        try:
            import unicodedata
            unicodedata.numeric(s)
            result = True
        except (TypeError, ValueError):
            pass

    return result 
开发者ID:ozhiwei,项目名称:SmartProxyPool,代码行数:19,代码来源:ConfigManager.py

示例7: is_number

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass

    return False
#---------------------------------------------------------------------- 
开发者ID:Esri,项目名称:utilities-solution-data-automation,代码行数:18,代码来源:common.py

示例8: is_number

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def is_number(s):
    """
    Helper function to detect numbers

    Args:
        s: a string

    Returns:
        bool: True if s is a number
    """
    try:
        float(s)
        return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass

    return False 
开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:26,代码来源:visualize_pySDC_with_PETSc.py

示例9: is_number

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def is_number(string):
    """Also accepts '.' in the string. Function 'isnumeric()' doesn't"""
    try:
        float(string)
        return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(string)
        return True
    except (TypeError, ValueError):
        pass

    return False 
开发者ID:Endogen,项目名称:OpenCryptoBot,代码行数:18,代码来源:utils.py

示例10: isNumber

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def isNumber(s):
    """
    Determines if a unicode string (that may include commas) is a number.

    :param s: Any unicode string.
    :return: True if s represents a number, False otherwise.
    """
    s = s.replace(',', '')
    try:
        float(s)
        return True
    except ValueError:
        pass
    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError) as e:
        pass
    return False 
开发者ID:DataBiosphere,项目名称:toil,代码行数:22,代码来源:ec2nodes.py

示例11: is_number

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass
 
    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass
 
    return False

#主要程序部分 
开发者ID:q158073378252010,项目名称:v2ray.fun,代码行数:19,代码来源:changeport.py

示例12: is_number

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass
 
    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass
 
    return False

#读取配置文件信息 
开发者ID:q158073378252010,项目名称:v2ray.fun,代码行数:19,代码来源:changestream.py

示例13: is_number

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass

    return False



# Take image function 
开发者ID:kmhmubin,项目名称:Face-Recognition-Attendance-System,代码行数:21,代码来源:Capture_Image.py

示例14: is_number

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass

    return False
######################################################################################################################## 
开发者ID:joansj,项目名称:hat,代码行数:18,代码来源:utils.py

示例15: fraction_to_float

# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def fraction_to_float(fraction: str) -> float:
    """Convert string representation of a fraction to float.

    Also supports unicode characters.

    Args:
        fraction (str): String representation of fraction, ie. "3/4", "1 1/2", etc.

    Returns:
        float: Converted fraction
    """
    # For fractions with weird divider character (ie. "1⁄2")
    fraction = fraction.replace("⁄", "/")

    try:
        # Convert unicode fractions (ie. "½")
        fraction_out = unicodedata.numeric(fraction)
    except TypeError:
        try:
            # Convert normal fraction (ie. "1/2")
            fraction_out = float(sum(Fraction(s) for s in fraction.split()))
        except ValueError:
            # Convert combined fraction with unicode (ie. "1 ½")
            fraction_split = fraction.split()
            fraction_out = float(fraction_split[0]) + unicodedata.numeric(
                fraction_split[1]
            )

    return fraction_out 
开发者ID:justinmklam,项目名称:recipe-converter,代码行数:31,代码来源:utils.py


注:本文中的unicodedata.numeric方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。