Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我从套接字接收一个 MAC 地址,格式如下:0024e865a023(使用接收字符串.encode(“hex”)从二进制转换的十六进制)
我想将其转换为用户可读的格式,如下所示:00-24-e8-65-a0-23
有什么简单的方法吗?
您可以将 MAC 地址分解为每个块的数组,然后将它们加入-:
-
mac = '0024e865a023' blocks = [mac[x:x+2] for x in xrange(0, len(mac), 2)] macFormatted = '-'.join(blocks)