本文整理匯總了Python中__builtin__.unicode方法的典型用法代碼示例。如果您正苦於以下問題:Python __builtin__.unicode方法的具體用法?Python __builtin__.unicode怎麽用?Python __builtin__.unicode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類__builtin__
的用法示例。
在下文中一共展示了__builtin__.unicode方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _decode_line
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import unicode [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
示例2: __init__
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import unicode [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
#
示例3: __init__
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import unicode [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
#
示例4: __init__
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import unicode [as 別名]
def __init__(self, delimiter=None, comments=b'#', 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
#
示例5: test_retrieves_version_of_self
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import unicode [as 別名]
def test_retrieves_version_of_self(self):
pkg_version = version('egginfo-pkg')
assert isinstance(pkg_version, text)
assert re.match(self.version_pattern, pkg_version)
示例6: test_retrieves_version_of_distinfo_pkg
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import unicode [as 別名]
def test_retrieves_version_of_distinfo_pkg(self):
pkg_version = version('distinfo-pkg')
assert isinstance(pkg_version, text)
assert re.match(self.version_pattern, pkg_version)
示例7: test_retrieves_version_of_self
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import unicode [as 別名]
def test_retrieves_version_of_self(self):
dist = Distribution.from_name('distinfo-pkg')
assert isinstance(dist.version, text)
assert re.match(self.version_pattern, dist.version)
示例8: _str
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import unicode [as 別名]
def _str(s, encoding="UTF-8"):
return unicode(s, encoding=encoding)
示例9: unicode
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import unicode [as 別名]
def unicode(s): # pylint: disable=invalid-name
"""Force conversion of s to unicode."""
return __builtin__.unicode(s, 'utf-8')
# In Python 3.2+, readfp is deprecated in favor of read_file, which doesn't
# exist in Python 2 yet. To avoid deprecation warnings, subclass ConfigParser to
# fix this - now read_file works across all Python versions we care about.