Python unicodedata.numeric() Examples

The following are 30 code examples of unicodedata.numeric(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module unicodedata , or try the search function .
Example #1
Source File: test_regressions.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
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'), '') 
Example #2
Source File: changeport.py    From v2ray.fun with GNU General Public License v3.0 6 votes vote down vote up
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

#主要程序部分 
Example #3
Source File: ec2nodes.py    From toil with Apache License 2.0 6 votes vote down vote up
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 
Example #4
Source File: changestream.py    From v2ray.fun with GNU General Public License v3.0 6 votes vote down vote up
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

#读取配置文件信息 
Example #5
Source File: utils.py    From OpenCryptoBot with GNU Affero General Public License v3.0 6 votes vote down vote up
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 
Example #6
Source File: changesecurity.py    From v2ray.fun with GNU General Public License v3.0 6 votes vote down vote up
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

#主要程序部分 
Example #7
Source File: visualize_pySDC_with_PETSc.py    From pySDC with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 
Example #8
Source File: test_regressions.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
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'), '') 
Example #9
Source File: Capture_Image.py    From Face-Recognition-Attendance-System with MIT License 6 votes vote down vote up
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 
Example #10
Source File: common.py    From utilities-solution-data-automation with Apache License 2.0 6 votes vote down vote up
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
#---------------------------------------------------------------------- 
Example #11
Source File: utils.py    From hat with MIT License 6 votes vote down vote up
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
######################################################################################################################## 
Example #12
Source File: ConfigManager.py    From SmartProxyPool with MIT License 6 votes vote down vote up
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 
Example #13
Source File: common.py    From ArcREST with Apache License 2.0 6 votes vote down vote up
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
#---------------------------------------------------------------------- 
Example #14
Source File: DataContainer.py    From FAE with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #15
Source File: util.py    From kotori with GNU Affero General Public License v3.0 6 votes vote down vote up
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 
Example #16
Source File: util.py    From kotori with GNU Affero General Public License v3.0 6 votes vote down vote up
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 
Example #17
Source File: util.py    From mtgjson with MIT License 5 votes vote down vote up
def is_number(string: str) -> bool:
    """See if a given string is a number (int or float)"""
    try:
        float(string)
        return True
    except ValueError:
        pass

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

    return False 
Example #18
Source File: utils.py    From v2ray.fun with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #19
Source File: utils.py    From recipe-converter with MIT License 5 votes vote down vote up
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 
Example #20
Source File: riak.py    From integrations-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def safe_submit_metric(self, name, value, tags=None):
        tags = [] if tags is None else tags
        try:
            self.gauge(name, float(value), tags=tags)
            return
        except ValueError:
            self.log.debug("metric name %s cannot be converted to a float: %s", name, value)
            pass

        try:
            self.gauge(name, unicodedata.numeric(value), tags=tags)
            return
        except (TypeError, ValueError):
            self.log.debug("metric name %s cannot be converted to a float even using unicode tools: %s", name, value)
            pass 
Example #21
Source File: util_micro_table.py    From SemAIDA with Apache License 2.0 5 votes vote down vote up
def To_Number(cell):
    if cell.lower() == 'nan' or cell.lower() == 'inf':
        return 0.0
    try:
        v = float(cell)
        return v
    except ValueError:
        pass
    try:
        v = unicodedata.numeric(cell)
        return v
    except (TypeError, ValueError):
        pass
    return 0.0 
Example #22
Source File: util_micro_table.py    From SemAIDA with Apache License 2.0 5 votes vote down vote up
def Is_Number(s):
    num_flag = False
    try:
        float(s)
        num_flag = True
    except ValueError:
        pass
    if not num_flag:
        try:
            unicodedata.numeric(s)
            num_flag = True
        except (TypeError, ValueError):
            pass
    return num_flag 
Example #23
Source File: helper.py    From HyTE with Apache License 2.0 5 votes vote down vote up
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 
Example #24
Source File: common.py    From neural_sequence_labeling with MIT License 5 votes vote down vote up
def is_digit(word):
    try:
        float(word)
        return True
    except ValueError:
        pass
    try:
        unicodedata.numeric(word)
        return True
    except (TypeError, ValueError):
        pass
    result = re.compile(r'^[-+]?[0-9]+,[0-9]+$').match(word)
    if result:
        return True
    return False 
Example #25
Source File: riak_repl.py    From integrations-extras with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def safe_submit_metric(self, name, value, tags=None):
        tags = [] if tags is None else tags
        try:
            self.gauge(name, float(value), tags=tags)
            return
        except ValueError:
            self.log.debug("metric name %s cannot be converted to a float: %s", name, value)

        try:
            self.gauge(name, unicodedata.numeric(value), tags=tags)
            return
        except (TypeError, ValueError):
            self.log.debug("metric name %s cannot be converted to a float even using unicode tools: %s", name, value) 
Example #26
Source File: common.py    From codo-cmdb with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #27
Source File: utils.py    From Mobile-Security-Framework-MobSF with GNU General Public License v3.0 5 votes vote down vote up
def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass
    try:
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass
    return False 
Example #28
Source File: utils.py    From MobileSF with GNU General Public License v3.0 5 votes vote down vote up
def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass
    try:
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass
    return False 
Example #29
Source File: utils.py    From UCB with MIT License 5 votes vote down vote up
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
######################################################################################################################## 
Example #30
Source File: utils.py    From MultiKE with MIT License 5 votes vote down vote up
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