为什么我不能迭代二进制多行读取?

2024-09-27 04:20:36 发布

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

我想用Python来读末日之书。我从Doombuilder中保存了一些随机的基本WAD,我正在尝试阅读它。你知道吗

wad = open("test.wad","rb")

如果我打印readlines():

print wad.readlines()

输出:

['PWAD\x0b\x00\x00\x00U\x01\x00\x00`\xff`\xff\x0e\x01\x01\x00\x07\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\xff\xff\x02\x00\x01\x00\x01\x00\x00\x00\x00\x00\x01\x00\xff\xff\x03\x00\x02\x00\x01\x00\x00\x00\x00\x00\x02\x00\xff\xff\x00\x00\x03\x00\x01\x00\x00\x00\x00\x00\x03\x00\xff\xff\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00STARTAN2\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00STARTAN2\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00STARTAN2\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00STARTAN2\x00\x00\x00\xff\xc0\xff\x00\xff\x00\xff\xc0\xff\x00\xff\xc0\xff\xc0\xff\x01\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x02\x00\x01\x00\x00\x80\x01\x00\x00\x00\x00\x00\x03\x00\x02\x00\x00\xc0\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x80\x00FLOOR0_1CEIL1_1\x00\xc0\x00\x00\x00\x00\x00\x01\xf8\xfe\xf8\xfe\x02\x00\x02\x00\x08\x00\x0c\x00\x10\x00\x14\x00\x00\x00\x00\x00\x01\x00\xff\xff\x00\x00\x01\x00\x02\x00\xff\xff\x00\x00\x00\x00\x03\x00\xff\xff\x00\x00\x02\x00\x03\x00\xff\xff\x0c\x00\x00\x00\x00\x00\x00\x00MAP01\x00\x00\x00\x0c\x00\x00\x00\n', '\x00\x00\x00THINGS\x00\x00\x16\x00\x00\x008\x00\x00\x00LINEDEFSN\x00\x00\x00x\x00\x00\x00SIDEDEFS\xc6\x00\x00\x00\x10\x00\x00\x00VERTEXES\xd6\x00\x00\x000\x00\x00\x00SEGS\x00\x00\x00\x00\x06\x01\x00\x00\x04\x00\x00\x00SSECTORS\n', '\x01\x00\x00\x00\x00\x00\x00NODES\x00\x00\x00\n', '\x01\x00\x00\x1a\x00\x00\x00SECTORS\x00$\x01\x00\x00\x01\x00\x00\x00REJECT\x00\x00%\x01\x00\x000\x00\x00\x00BLOCKMAP']

它返回一个带字符串的列表。你知道吗

现在,如果我迭代它:

for i in wad.readlines():
    print i

输出:

PWAD

刚刚开始。为什么?你知道吗

我得到的结果和以前的一样:

x = wad.readlines()
for i in x:
    print i

这里是下载文件的链接(Mediafire):

https://www.mediafire.com/?hvrcmwv1vcwvo29


Tags: printx00x04x03x01x02xffwad
1条回答
网友
1楼 · 发布于 2024-09-27 04:20:36
with open('test.wad','r') as file:
    for line in file:
        print repr(line)


#output 'PWAD\x0b\x00\x00\x00U\x01\x00\x00`\xff`\xff\x0e\x01\x01\x00\x07\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\xff\xff\x02\x00\x01\x00\x01\x00\x00\x00\x00\x00\x01\x00\xff\xff\x03\x00\x02\x00\x01\x00\x00\x00\x00\x00\x02\x00\xff\xff\x00\x00\x03\x00\x01\x00\x00\x00\x00\x00\x03\x00\xff\xff\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00STARTAN2\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00STARTAN2\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00STARTAN2\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00STARTAN2\x00\x00\x00\xff\xc0\xff\x00\xff\x00\xff\xc0\xff\x00\xff\xc0\xff\xc0\xff\x01\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x02\x00\x01\x00\x00\x80\x01\x00\x00\x00\x00\x00\x03\x00\x02\x00\x00\xc0\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x80\x00FLOOR0_1CEIL1_1\x00\xc0\x00\x00\x00\x00\x00\x01\xf8\xfe\xf8\xfe\x02\x00\x02\x00\x08\x00\x0c\x00\x10\x00\x14\x00\x00\x00\x00\x00\x01\x00\xff\xff\x00\x00\x01\x00\x02\x00\xff\xff\x00\x00\x00\x00\x03\x00\xff\xff\x00\x00\x02\x00\x03\x00\xff\xff\x0c\x00\x00\x00\x00\x00\x00\x00MAP01\x00\x00\x00\x0c\x00\x00\x00\n'
'\x00\x00\x00THINGS\x00\x00\x16\x00\x00\x008\x00\x00\x00LINEDEFSN\x00\x00\x00x\x00\x00\x00SIDEDEFS\xc6\x00\x00\x00\x10\x00\x00\x00VERTEXES\xd6\x00\x00\x000\x00\x00\x00SEGS\x00\x00\x00\x00\x06\x01\x00\x00\x04\x00\x00\x00SSECTORS\n'
'\x01\x00\x00\x00\x00\x00\x00NODES\x00\x00\x00\n'
'\x01\x00\x00'

相关问题 更多 >

    热门问题