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


Python __builtin__.str方法代碼示例

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


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

示例1: __new__

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import str [as 別名]
def __new__(mcls, enum_type, *args, **kwds):
        """
        Creates an ArsdkBitfield type from its associated enum type
        """
        if ArsdkBitfieldMeta._base is None:
            cls = type.__new__(
                ArsdkBitfieldMeta, builtin_str("ArsdkBitfield"), *args, **kwds)
            mcls._base = cls
        else:
            cls = mcls._classes.get(enum_type)
            if cls is not None:
                return cls
            cls = type.__new__(
                mcls,
                builtin_str(enum_type.__name__ + "_Bitfield"),
                (mcls._base,),
                dict(_enum_type_=enum_type))
            mcls._classes[enum_type] = cls
        return cls 
開發者ID:Parrot-Developers,項目名稱:olympe,代碼行數:21,代碼來源:enums.py

示例2: _decode_line

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import str [as 別名]
def _decode_line(line, encoding=None):
    """Decode bytes from binary input streams.

    Defaults to decoding from 'latin1'. That differs from the behavior of
    np.compat.asunicode that decodes from 'ascii'.

    Parameters
    ----------
    line : str or bytes
         Line to be decoded.

    Returns
    -------
    decoded_line : unicode
         Unicode in Python 2, a str (unicode) in Python 3.

    """
    if type(line) is bytes:
        if encoding is None:
            line = line.decode('latin1')
        else:
            line = line.decode(encoding)

    return line 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:_iotools.py

示例3: __init__

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import str [as 別名]
def __init__(self, jss):
        """Initialize a Casper object.

        Args:
            jss: A JSS object to request the casper page from.
        """
        self.jss = jss
        self.url = "%s/casper.jxml" % self.jss.base_url

        # This may be incorrect, but the assumption here is that this
        # request wants the auth information as urlencoded data; and
        # urlencode needs bytes.
        # TODO: If we can just pass in bytes rather than
        # urlencoded-bytes, we can remove this and let the request
        # adapter handle the outgoing data encoding.
        user = text(self.jss.user)
        password = text(self.jss.password)
        self.auth = urlencode(
            {"username": user, "password": password})
        super(Casper, self).__init__("Casper")
        self.update() 
開發者ID:jssimporter,項目名稱:python-jss,代碼行數:23,代碼來源:casper.py

示例4: str2bool

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import str [as 別名]
def str2bool(value):
    """
    Tries to transform a string supposed to represent a boolean to a boolean.

    Parameters
    ----------
    value : str
        The string that is transformed to a boolean.

    Returns
    -------
    boolval : bool
        The boolean representation of `value`.

    Raises
    ------
    ValueError
        If the string is not 'True' or 'False' (case independent)

    Examples
    --------
    >>> np.lib._iotools.str2bool('TRUE')
    True
    >>> np.lib._iotools.str2bool('false')
    False

    """
    value = value.upper()
    if value == 'TRUE':
        return True
    elif value == 'FALSE':
        return False
    else:
        raise ValueError("Invalid boolean") 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:36,代碼來源:_iotools.py

示例5: issubsctype

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import str [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:Frank-qlu,項目名稱:recruit,代碼行數:31,代碼來源:numerictypes.py

示例6: write

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import str [as 別名]
def write(self, x):
        old_f.write(x.replace("\n", " [%s]\n" % str(datetime.now()))) 
開發者ID:LuciferJack,項目名稱:python-mysql-pool,代碼行數:4,代碼來源:log_util.py

示例7: underline_print

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import str [as 別名]
def underline_print(string):
    under_str = "\033[4m%s\033[0m" % (str(string),)
    return under_str 
開發者ID:LuciferJack,項目名稱:python-mysql-pool,代碼行數:5,代碼來源:log_util.py

示例8: str2bool

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import str [as 別名]
def str2bool(value):
    """
    Tries to transform a string supposed to represent a boolean to a boolean.

    Parameters
    ----------
    value : str
        The string that is transformed to a boolean.

    Returns
    -------
    boolval : bool
        The boolean representation of `value`.

    Raises
    ------
    ValueError
        If the string is not 'True' or 'False' (case independent)

    Examples
    --------
    >>> np.lib._iotools.str2bool('TRUE')
    True
    >>> np.lib._iotools.str2bool('false')
    False

    """
    value = value.upper()
    if value == asbytes('TRUE'):
        return True
    elif value == asbytes('FALSE'):
        return False
    else:
        raise ValueError("Invalid boolean") 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:36,代碼來源:_iotools.py

示例9: setUp

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import str [as 別名]
def setUp(self):
        self.s = TEST_UNICODE_STR
        self.s2 = str(self.s)
        self.b = b'ABCDEFG'
        self.b2 = bytes(self.b) 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:7,代碼來源:test_utils.py

示例10: test_native_str

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import str [as 別名]
def test_native_str(self):
        """
        Tests whether native_str is really equal to the platform str.
        """
        if PY2:
            import __builtin__
            builtin_str = __builtin__.str
        else:
            import builtins
            builtin_str = builtins.str

        inputs = [b'blah', u'blah', 'blah']
        for s in inputs:
            self.assertEqual(native_str(s), builtin_str(s))
            self.assertTrue(isinstance(native_str(s), builtin_str)) 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:17,代碼來源:test_utils.py

示例11: test_native

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import str [as 別名]
def test_native(self):   
        a = int(10**20)     # long int
        b = native(a)
        self.assertEqual(a, b)
        if PY2:
            self.assertEqual(type(b), long)
        else:
            self.assertEqual(type(b), int)
    
        c = bytes(b'ABC')
        d = native(c)
        self.assertEqual(c, d)
        if PY2:
            self.assertEqual(type(d), type(b'Py2 byte-string'))
        else:
            self.assertEqual(type(d), bytes)
    
        s = str(u'ABC')
        t = native(s)
        self.assertEqual(s, t)
        if PY2:
            self.assertEqual(type(t), unicode)
        else:
            self.assertEqual(type(t), str)

        d1 = dict({'a': 1, 'b': 2})
        d2 = native(d1)
        self.assertEqual(d1, d2)
        self.assertEqual(type(d2), type({})) 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:31,代碼來源:test_utils.py

示例12: test_raise_

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import str [as 別名]
def test_raise_(self):
        """
        The with_value() test currently fails on Py3
        """
        def valerror():
            try:
                raise ValueError("Apples!")
            except Exception as e:
                raise_(e)

        self.assertRaises(ValueError, valerror)

        def with_value():
            raise_(IOError, "This is an error")

        self.assertRaises(IOError, with_value)

        try:
            with_value()
        except IOError as e:
            self.assertEqual(str(e), "This is an error")

        def with_traceback():
            try:
                raise ValueError("An error")
            except Exception as e:
                _, _, traceback = sys.exc_info()
                raise_(IOError, str(e), traceback)

        self.assertRaises(IOError, with_traceback)

        try:
            with_traceback()
        except IOError as e:
            self.assertEqual(str(e), "An error") 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:37,代碼來源:test_utils.py

示例13: test_ensure_new_type

# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import str [as 別名]
def test_ensure_new_type(self):
        s = u'abcd'
        s2 = str(s)
        self.assertEqual(ensure_new_type(s), s2)
        self.assertEqual(type(ensure_new_type(s)), str)

        b = b'xyz'
        b2 = bytes(b)
        self.assertEqual(ensure_new_type(b), b2)
        self.assertEqual(type(ensure_new_type(b)), bytes)

        i = 10000000000000
        i2 = int(i)
        self.assertEqual(ensure_new_type(i), i2)
        self.assertEqual(type(ensure_new_type(i)), int) 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:17,代碼來源:test_utils.py


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