本文整理匯總了Python中__builtin__.ord方法的典型用法代碼示例。如果您正苦於以下問題:Python __builtin__.ord方法的具體用法?Python __builtin__.ord怎麽用?Python __builtin__.ord使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類__builtin__
的用法示例。
在下文中一共展示了__builtin__.ord方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_mac_address
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import ord [as 別名]
def get_mac_address(ifname):
import fcntl
ifname = ifname[:15]
if PY3:
ifname = bytes(ifname, 'ascii')
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
with contextlib.closing(s):
info = fcntl.ioctl(
s.fileno(), SIOCGIFHWADDR, struct.pack('256s', ifname))
if PY3:
def ord(x):
return x
else:
import __builtin__
ord = __builtin__.ord
return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
示例2: kernel_disconnect_workarounds
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import ord [as 別名]
def kernel_disconnect_workarounds(self, data):
#print 'PRE KERNEL WORKAROUND %d' % len(data)
def noop(value):
return value
if (sys.version_info > (3, 0)):
ord = noop
else:
import __builtin__
ord = __builtin__.ord
if len(data) == 22 and [ord(elem) for elem in data[0:5]] == [0x04, 0x3e, 0x13, 0x01, 0x00]:
handle = ord(data[5])
# get address
set = data[9:15]
# get device info
dev_info = self.get_device_info()
raw_set = [ord(c) for c in set]
raw_set.reverse()
#addz = ''.join([hex(c) for c in set])
#set.reverse()
addz = "%02x:%02x:%02x:%02x:%02x:%02x" % struct.unpack("BBBBBB", array.array('B', raw_set))
socket2 = BluetoothSocket(socket.AF_BLUETOOTH, socket.SOCK_SEQPACKET, socket.BTPROTO_L2CAP)
socket2.bind_l2(0, dev_info['addr'], cid=ATT_CID, addr_type=0)#addr_type=dev_info['type'])
self._l2sockets[handle] = socket2
try:
result = socket2.connect_l2(0, addz, cid=ATT_CID, addr_type=ord(data[8]) + 1)
except:
pass
elif len(data) == 7 and [ord(elem) for elem in data[0:4]] == [0x04, 0x05, 0x04, 0x00]:
handle = ord(data[4])
socket2 = self._l2sockets[handle] if handle in self._l2sockets else None
if socket2:
# print 'GOT A SOCKET!'
socket2.close()
del self._l2sockets[handle]
示例3: ord
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import ord [as 別名]
def ord(char):
""" returns unicode id for utf8 or unicode *char* character
SUPPOSE that *char* is an utf-8 or unicode character only
"""
if isinstance(char, unicode):
return __builtin__.ord(char)
return __builtin__.ord(unicode(char, 'utf-8'))