當前位置: 首頁>>代碼示例>>Python>>正文


Python __builtin__.int方法代碼示例

本文整理匯總了Python中__builtin__.int方法的典型用法代碼示例。如果您正苦於以下問題:Python __builtin__.int方法的具體用法?Python __builtin__.int怎麽用?Python __builtin__.int使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在__builtin__的用法示例。


在下文中一共展示了__builtin__.int方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _strict_call

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import int [as 別名]
def _strict_call(self, value):
        try:

            # We check if we can convert the value using the current function
            new_value = self.func(value)

            # In addition to having to check whether func can convert the
            # value, we also have to make sure that we don't get overflow
            # errors for integers.
            if self.func is int:
                try:
                    np.array(value, dtype=self.type)
                except OverflowError:
                    raise ValueError

            # We're still here so we can now return the new value
            return new_value

        except ValueError:
            if value.strip() in self.missing_values:
                if not self._status:
                    self._checked = False
                return self.default
            raise ValueError("Cannot convert string '%s'" % value)
    # 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:27,代碼來源:_iotools.py

示例2: _set_array_types

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import int [as 別名]
def _set_array_types():
    ibytes = [1, 2, 4, 8, 16, 32, 64]
    fbytes = [2, 4, 8, 10, 12, 16, 32, 64]
    for bytes in ibytes:
        bits = 8*bytes
        _add_array_type('int', bits)
        _add_array_type('uint', bits)
    for bytes in fbytes:
        bits = 8*bytes
        _add_array_type('float', bits)
        _add_array_type('complex', 2*bits)
    _gi = dtype('p')
    if _gi.type not in sctypes['int']:
        indx = 0
        sz = _gi.itemsize
        _lst = sctypes['int']
        while (indx < len(_lst) and sz >= _lst[indx](0).itemsize):
            indx += 1
        sctypes['int'].insert(indx, _gi.type)
        sctypes['uint'].insert(indx, dtype('P').type) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:22,代碼來源:numerictypes.py

示例3: __init__

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import int [as 別名]
def __init__(self, delimiter=None, comments=asbytes('#'), autostrip=True):
        self.comments = comments
        # Delimiter is a character
        if isinstance(delimiter, unicode):
            delimiter = delimiter.encode('ascii')
        if (delimiter is None) or _is_bytes_like(delimiter):
            delimiter = delimiter or None
            _handyman = self._delimited_splitter
        # Delimiter is a list of field widths
        elif hasattr(delimiter, '__iter__'):
            _handyman = self._variablewidth_splitter
            idx = np.cumsum([0] + list(delimiter))
            delimiter = [slice(i, j) for (i, j) in zip(idx[:-1], idx[1:])]
        # Delimiter is a single integer
        elif int(delimiter):
            (_handyman, delimiter) = (
                    self._fixedwidth_splitter, int(delimiter))
        else:
            (_handyman, delimiter) = (self._delimited_splitter, None)
        self.delimiter = delimiter
        if autostrip:
            self._handyman = self.autostrip(_handyman)
        else:
            self._handyman = _handyman
    # 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:27,代碼來源:_iotools.py

示例4: __init__

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import int [as 別名]
def __init__(self, delimiter=None, comments=asbytes('#'), autostrip=True):
        self.comments = comments
        # Delimiter is a character
        if isinstance(delimiter, unicode):
            delimiter = delimiter.encode('ascii')
        if (delimiter is None) or _is_bytes_like(delimiter):
            delimiter = delimiter or None
            _handyman = self._delimited_splitter
        # Delimiter is a list of field widths
        elif hasattr(delimiter, '__iter__'):
            _handyman = self._variablewidth_splitter
            idx = np.cumsum([0] + list(delimiter))
            delimiter = [slice(i, j) for (i, j) in zip(idx[:-1], idx[1:])]
        # Delimiter is a single integer
        elif int(delimiter):
            (_handyman, delimiter) = (self._fixedwidth_splitter, int(delimiter))
        else:
            (_handyman, delimiter) = (self._delimited_splitter, None)
        self.delimiter = delimiter
        if autostrip:
            self._handyman = self.autostrip(_handyman)
        else:
            self._handyman = _handyman
    # 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:26,代碼來源:_iotools.py

示例5: flatten_dtype

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import int [as 別名]
def flatten_dtype(ndtype, flatten_base=False):
    """
    Unpack a structured data-type by collapsing nested fields and/or fields
    with a shape.

    Note that the field names are lost.

    Parameters
    ----------
    ndtype : dtype
        The datatype to collapse
    flatten_base : bool, optional
       If True, transform a field with a shape into several fields. Default is
       False.

    Examples
    --------
    >>> dt = np.dtype([('name', 'S4'), ('x', float), ('y', float),
    ...                ('block', int, (2, 3))])
    >>> np.lib._iotools.flatten_dtype(dt)
    [dtype('|S4'), dtype('float64'), dtype('float64'), dtype('int32')]
    >>> np.lib._iotools.flatten_dtype(dt, flatten_base=True)
    [dtype('|S4'), dtype('float64'), dtype('float64'), dtype('int32'),
     dtype('int32'), dtype('int32'), dtype('int32'), dtype('int32'),
     dtype('int32')]

    """
    names = ndtype.names
    if names is None:
        if flatten_base:
            return [ndtype.base] * int(np.prod(ndtype.shape))
        return [ndtype.base]
    else:
        types = []
        for field in names:
            info = ndtype.fields[field]
            flat_dt = flatten_dtype(info[0], flatten_base)
            types.extend(flat_dt)
        return types 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:41,代碼來源:_iotools.py

示例6: __init__

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import int [as 別名]
def __init__(self, delimiter=None, comments='#', autostrip=True, encoding=None):
        delimiter = _decode_line(delimiter)
        comments = _decode_line(comments)

        self.comments = comments

        # Delimiter is a character
        if (delimiter is None) or isinstance(delimiter, basestring):
            delimiter = delimiter or None
            _handyman = self._delimited_splitter
        # Delimiter is a list of field widths
        elif hasattr(delimiter, '__iter__'):
            _handyman = self._variablewidth_splitter
            idx = np.cumsum([0] + list(delimiter))
            delimiter = [slice(i, j) for (i, j) in zip(idx[:-1], idx[1:])]
        # Delimiter is a single integer
        elif int(delimiter):
            (_handyman, delimiter) = (
                    self._fixedwidth_splitter, int(delimiter))
        else:
            (_handyman, delimiter) = (self._delimited_splitter, None)
        self.delimiter = delimiter
        if autostrip:
            self._handyman = self.autostrip(_handyman)
        else:
            self._handyman = _handyman
        self.encoding = encoding
    # 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:30,代碼來源:_iotools.py

示例7: issubclass_

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import int [as 別名]
def issubclass_(arg1, arg2):
    """
    Determine if a class is a subclass of a second class.

    `issubclass_` is equivalent to the Python built-in ``issubclass``,
    except that it returns False instead of raising a TypeError if one
    of the arguments is not a class.

    Parameters
    ----------
    arg1 : class
        Input class. True is returned if `arg1` is a subclass of `arg2`.
    arg2 : class or tuple of classes.
        Input class. If a tuple of classes, True is returned if `arg1` is a
        subclass of any of the tuple elements.

    Returns
    -------
    out : bool
        Whether `arg1` is a subclass of `arg2` or not.

    See Also
    --------
    issubsctype, issubdtype, issctype

    Examples
    --------
    >>> np.issubclass_(np.int32, int)
    True
    >>> np.issubclass_(np.int32, float)
    False

    """
    try:
        return issubclass(arg1, arg2)
    except TypeError:
        return False 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:39,代碼來源:numerictypes.py

示例8: _evalname

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import int [as 別名]
def _evalname(name):
    k = 0
    for ch in name:
        if ch in '0123456789':
            break
        k += 1
    try:
        bits = int(name[k:])
    except ValueError:
        bits = 0
    base = name[:k]
    return base, bits 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:14,代碼來源:numerictypes.py

示例9: _add_aliases

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import int [as 別名]
def _add_aliases():
    for type_name, info in typeinfo.items():
        if isinstance(info, type):
            continue
        name = english_lower(type_name)

        # insert bit-width version for this class (if relevant)
        base, bit, char = bitname(info.type)
        if base[-3:] == 'int' or char[0] in 'ui':
            continue
        if base != '':
            myname = "%s%d" % (base, bit)
            if (name not in ('longdouble', 'clongdouble') or
                   myname not in allTypes):
                base_capitalize = english_capitalize(base)
                if base == 'complex':
                    na_name = '%s%d' % (base_capitalize, bit//2)
                elif base == 'bool':
                    na_name = base_capitalize
                else:
                    na_name = "%s%d" % (base_capitalize, bit)

                allTypes[myname] = info.type

                # add mapping for both the bit name and the numarray name
                sctypeDict[myname] = info.type
                sctypeDict[na_name] = info.type

                # add forward, reverse, and string mapping to numarray
                sctypeNA[na_name] = info.type
                sctypeNA[info.type] = na_name
                sctypeNA[info.char] = na_name
        if char != '':
            sctypeDict[char] = info.type
            sctypeNA[char] = na_name 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:37,代碼來源:numerictypes.py

示例10: issubsctype

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import int [as 別名]
def issubsctype(arg1, arg2):
    """
    Determine if the first argument is a subclass of the second argument.

    Parameters
    ----------
    arg1, arg2 : dtype or dtype specifier
        Data-types.

    Returns
    -------
    out : bool
        The result.

    See Also
    --------
    issctype, issubdtype,obj2sctype

    Examples
    --------
    >>> np.issubsctype('S8', str)
    True
    >>> np.issubsctype(np.array([1]), int)
    True
    >>> np.issubsctype(np.array([1]), float)
    False

    """
    return issubclass(obj2sctype(arg1), obj2sctype(arg2)) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:31,代碼來源:numerictypes.py

示例11: flatten_dtype

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import int [as 別名]
def flatten_dtype(ndtype, flatten_base=False):
    """
    Unpack a structured data-type by collapsing nested fields and/or fields
    with a shape.

    Note that the field names are lost.

    Parameters
    ----------
    ndtype : dtype
        The datatype to collapse
    flatten_base : {False, True}, optional
        Whether to transform a field with a shape into several fields or not.

    Examples
    --------
    >>> dt = np.dtype([('name', 'S4'), ('x', float), ('y', float),
    ...                ('block', int, (2, 3))])
    >>> np.lib._iotools.flatten_dtype(dt)
    [dtype('|S4'), dtype('float64'), dtype('float64'), dtype('int32')]
    >>> np.lib._iotools.flatten_dtype(dt, flatten_base=True)
    [dtype('|S4'), dtype('float64'), dtype('float64'), dtype('int32'),
     dtype('int32'), dtype('int32'), dtype('int32'), dtype('int32'),
     dtype('int32')]

    """
    names = ndtype.names
    if names is None:
        if flatten_base:
            return [ndtype.base] * int(np.prod(ndtype.shape))
        return [ndtype.base]
    else:
        types = []
        for field in names:
            info = ndtype.fields[field]
            flat_dt = flatten_dtype(info[0], flatten_base)
            types.extend(flat_dt)
        return types 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:40,代碼來源:_iotools.py


注:本文中的__builtin__.int方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。