使用python将二进制数字分隔为excel行

2024-09-22 16:28:54 发布

您现在位置:Python中文网/ 问答频道 /正文

实际上,我正在创建一个列表,其中我将整数转换为具有8位表示的二进制数字,并将二进制数据写入excel电子表格:

row = 3
for x in MyList:
    mybinary = bin(x)[2:].zfill(8)  
    ws.write(r,2,mybinary)
    row+=1

结果如下: enter image description here

我希望达到的目标是: enter image description here

位应该具有相同的顺序,但只是从右侧开始在8行上排序

调试信息:

print(type(MyList))
<type 'list'>


print(type(x))
<type 'int'>
<type 'int'>
<type 'int'>
<type 'int'>
<type 'int'>

到目前为止,mybinary的输出是正常的(在excel工作表中输出的二进制字符串),并且转换正确

有什么想法吗


Tags: 数据in列表fortype二进制数字整数