當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。