首页 > 解决方案 > 如何将低端ascii字节(这样想)转换为python中的文本?

问题描述

最近,在我的大学项目将.dat文件转换为excel文件时,无论我尝试什么都无法转换它。我对python的经验很少,这种转换至关重要,否则我必须手动转换与其他软件。但我有超过 25000 个文件要转换。请帮助我。这是以二进制模式读取时的 .dat 文件内容

b'\x00\x00\xd0\x05\xdf)\x93EW\x1e\x90\xec\xa8K\xe5@\x00\x00t\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x009116-6631 \x00\x00\x00\x00\x00\x00                \x9c#\xe7\x19\x00\x00\x10\x00\x00\x00\x01\x00\x01\x00\x00\x00Default         \xff\xff\x00\x00\x10\x00\x00\x00\xff\xff\x00\x00b\x00\x00\x00\xff\xff\x00\x00\x80\x03\x00\x00\x1f\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00All Chan        \x00\x00\x10\x00\xff\xff\x00\x00\x00\xff(\x10\x00\x00\xf0A\xc0\xc0\xc0J\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P1    \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T1    \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P2    \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T2    \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P3    \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T3    \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P4    \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T4    \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P5    \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T5    \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P6    \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T6    \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P7    \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T7    \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P8    \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T8    \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P9    \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T9    \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P10   \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T10   \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P11   \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T11   \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P12   \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T12   \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P13   \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T13   \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P14   \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T14   \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P15   \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T15   \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xd7D\xd9\xa1\xdc@\x00\x00\x00\x00P16   \x00\x03kPa   \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00T16   \x02\x02degC  \x00\x00\x00\x00\x80?()    \x00\x00\x00\x00\x00\x00\x00\xff`\x00\x00\x00>=\x9c#\xe7\x19v\x02\x00\x00\xff\xff\xff\xff\x01\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00;9\xd9\xbe\nOy\xbe\x85_\xe5\xbf=Fx?z\x93\x17\xbfK\xda\xb4<t\xac\xb9<\x85}\t\xbf\x1a\xaf\xb7\xbfG\xb3\xd6=c\xc0\x00?\xd1W\x1d\xbf8\xfc\x82>\xce\x00\xf3\xbe\xf6sAAZ\xafRA\x00\xff\xe0\x00\x00\x00@=\x9c#\xe7\x19*\x00\x00\x00\xff\xff\xff\xff\x030\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x8b\xf1A@\n\xfcA\x80\x8f\xeeA\xc0;\xefA@\xa1\xf2A\xc03\xf1A\x80\xa0\xeeA\xc0\xa4\xefA\x80_\xf3A\xc0\xb8\xfbA\x80Q\xfbA\x80<\xf0A\x80d\xf3A\xc0k\xf1A\x003\xf2A\x80\xf4\xf0A\xfdY\xd9F\x02t\xe0F\xeeO\xe0F\x05\xba\xddF\xf4Q\xe0F\x02\x8e\xdfF\xf5Q\xdaF\xf4=\xdaF\xf1\x15\xd9F\x05\x86\xe0F\x02\x1c\xdfF\x01\x8c\xdcF\xfe\xa9\xdaF\x00.\xe0FMX\xdbFO\xb8\xdaFN\xd9\x87@\x9aI\x8c@\r3\x8c@X\x95\x8a@Q4\x8c@\xd9\xb9\x8b@Jt\x88@\xc9g\x88@\xc6\xae\x87@\xdcT\x8c@\x98r\x8b@\x94\xd8\x89@P\xab\x88@\xd8\x1d\x8c@B\x18\x89@C\xb4\x88@\x00\xff`\x00\x00 \x0c?\x9c#\xe7\x19w\x02\x00\x00\xff\xff\xff\xff\x01\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00^`N\xbf\x0cj\xad\xbe\xe5\x15\xd9\xbf\x9b\xbb_?z\x93\x17\xbf\xc5m\x97\xbdq;\xf2=\xc8\x85\x80\xbe\x13F\xb0\xbf\xa9\xc2\x97>\x08\xe7\x9f>\x1f\x88\xd8\xbe,\x8a\xb3>a\x02\xc2\xbe\xdb\nFA\x9b\xbfUA\x00\xff`\x00\x00@\x86?\x9c#\xe7\x19x\x02\x00\x00\xff\xff\xff\xff\x01\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00`\xef5\xbf\x1ew\x07\xbf\x89\x82\xc0\xbf\x9b\xbb_?M3\xfe\xbe\x0e\t.\xbeq;\xf2=\x85}\t\xbf\xeas\xa1\xbfXpM>65\x8d\xbd_\xe15\xbf\xd5\xf1\xfc\xbd\xce\x00\xf3\xbe\xdb\nFA\xfa\x16NA\x00\xff\xa0\x00\x00P\x86?\x9c#\xe7\x19\x9e\x00\x00\x00\xff\xff\x00\x00\x02 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x86C\x00\x00\xfeB\x00\x00\xe8B\x00\x00j\xc3\x00\x00\xf4B\x00\x00\xc0B\x00\x00\xba\xc2\x00\x00\x98A\x00\x00\x94\xc3\x00\x001\xc3\x00\x00\xe6B\x00\x00\xaaB\x00\x00\x88A\x00\x00DB\x00\x00\x10B\x00\x00\x80AO\x81\'=>\xc1\x9e<"\x01\x91<$A\x12\xbd1\x81\x98<\xe0\x01p<\xd1\x81h\xbc|\x01>;r\x019\xbd\xbaA\xdd\xbc \xc1\x8f<\xa9\x81T<T\x01*;\xea\x01\xf5;h\x01\xb4;@\x01 ;\x00\xff`\x00\x00`\xc6?\x9c#\xe7\x19y\x02\x00\x00\xff\xff\xff\xff\x01\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00l\'\r\xbe$,\xde\xbe\xe1\xf2\xfd\xbf=Fx?M\r0\xbf1\xd9\xf1=\x9c\x07[>\xff(\xe2\xbe\xdb\xa1\x92\xbf\xe3\xe7:\xbeW4(\xbe\x1f\x88\xd8\xbeAS\n?a\x02\xc2\xbe\x97\xfbBAZ\xafRA\x00\xff`\x00\x00H\x03@\x9c#\xe7\x19z\x02\x00\x00\xff\xff\xff\xff\x01\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00b~\x1d\xbf\x1ew\x07\xbfN\x1e\x05\xc0=Fx?M3\xfe\xbe/-\x88\xbe\xaah\x95\xbd{g\x1f\xbe0\xea\xcd\xbf\xbe<\x14<T4^>\xd1W\x1d\xbf8\xfc\x82>a\x02\xc2\xbe\xf6sAAZ\xafRA\x00\xff`\x00\x00X#@\x9c#\xe7\x19{\x02\x00\x00\xff\xff\xff\xff\x01\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00`\xef5\xbf\x0cj\xad\xbe\x85_\xe5\xbfoh\x88?\xe9\x86H\xbfK\xda\xb4<t\xac\xb9<\x8fO:\xbf\x13F\xb0\xbf\xd1\xa5\xb1\xbdc\xc0\x00?[kN\xbf\x12\xe8\xea\xbc\xd4~*\xbf\x97\xfbBA\x9b\xbfUA\x00\xff`\x00\x00pC@\x9c#\xe7\x19|\x02\x00\x00\xff\xff\xff\xff\x01\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xadW\xa8\xbe\nOy\xbe%\xa9\xf1\xbf\x9b\xbb_?\x14@\xcd\xbe\xc5m\x97\xbd\xaah\x95\xbd\x8fO:\xbf\xeas\xa1\xbf\xd1\xa5\xb1\xbdv3\xf9=\x1f\x88\xd8\xbe \x18\xe4>\x9d\xff\x11\xbfR\xec?A\xfa\x16NA\x00\xff\xa0\x00\x00\x80C@\x9c#\xe7\x19\x9f\x00\x00\x00\xff\xff\x00\x00\x02 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x88C\x00\x00\x02C\x00\x00\xe0B\x00\x00j\xc3\x00\x00\xf6B\x00\x00\xc2B\x00\x00\xbe\xc2\x00\x00\x88A\x00\x00\x94\xc3\x00\x004\xc3\x00\x00\xeaB\x00\x00\xb0B\x00\x00\xb8A\x00\x00@B\x00\x00\x00B\x00\x00\x80AT\x01*=E\x81\xa2<\x18\x01\x8c<$A\x12\xbd4\xc1\x99<\xe5\x81r<\xdb\x81m\xbcT\x01*;r\x019\xbd\xc2\x01\xe1\xbc$A\x92<\xb8\x01\\<\xcc\x01f;\xe0\x01\xf0;@\x01\xa0;@\x01 ;\x00\xff`\x00\x00\x80c@\x9c#\xe7\x19}\x02\x00\x00\xff\xff\xff\xff\x01\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00c\xebn\xbe\nOy\xbe\xe1\xf2\xfd\xbf=Fx?nL\x9c\xbe\xc5m\x97\xbdQx\x9e>\xff(\xe2\xbe"\x18\xbf\xbfXpM>\x08\xe7\x9f> \xf5f\xbf\xab\xdb$>\xce\x00\xf3\xbe\xf6sAA:\'QA\x00\x010\x00\xddF\x93Ez5\xf1\xec\xa8K\xe5@\x00\x00t\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00End File        '

这是我使用的代码

with open('data.dat'.'rb') as d:
    f=d.read()
    g=f.decode('utf-8')
    print(g)

我试过 utf-8、utf-16、latin-1、iso-8859-1 和 ascii。请帮帮我

标签: pythonbinaryasciistring-conversion

解决方案


推荐阅读