python - 我怎样才能摆脱这些“\xb0”之类的字符串
问题描述
我尝试使用 python 和 dll 从内存中转换一些数据。
但是有一些“unicode”的东西让我疯狂地使用结构来“转换”数据。
我试过decode('utf-8')
但我面对UnicodeDecodeError
我改变了一些结构类型,但没有任何改变。
我该如何解决这个问题?
class NH0__OutBlock(Structure):
_fields_ = [
("hotime", c_char*6),
("hotime1", c_char*6),
("offerho1", c_char*6),
("bidho1", c_char*6),
("offerrem1", c_char*6),
("bidrem1", c_char*6),
("offercnt1", c_char*5),
("bidcnt1", c_char*5),
("offerho2", c_char*6),
("bidho2", c_char*6),
("offerrem2", c_char*6),
("bidrem2", c_char*6),
("offercnt2", c_char*5),
("bidcnt2", c_char*5),
("offerho3", c_char*6),
("bidho3", c_char*6),
("offerrem3", c_char*6),
("bidrem3", c_char*6),
("offercnt3", c_char*5),
("bidcnt3", c_char*5),
("offerho4", c_char*6),
("bidho4", c_char*6),
("offerrem4", c_char*6),
("bidrem4", c_char*6),
("offercnt4", c_char*5),
("bidcnt4", c_char*5),
("offerho5", c_char*6),
("bidho5", c_char*6),
("offerrem5", c_char*6),
("bidrem5", c_char*6),
("offercnt5", c_char*5),
("bidcnt5", c_char*5),
("totofferrem", c_char*6),
("totbidrem", c_char*6),
("totoffercnt", c_char*5),
("totbidcnt", c_char*5),
("futcode", c_char*8)
]
...
# RealMsgPacket.contents.pszData Type is ctypes.c_char_p
elif RealMsgPacket.contents.szTrCode.decode('euc-kr') == "NH0":
Casted = cast(RealMsgPacket.contents.pszData, POINTER(c_char*int(RealMsgPacket.contents.nDataLength)))
print(Casted.contents.value.strip())
...
b'035822 275822 028345\xb0028340\xb0000012 000019 00004 00016 028350\xb0028335\xb0000014 000025 00007 00022 028355\xb002
8330\xb0000007 000020 00004 00015 028360\xb0028325\xb0000007 000022 00005 00011 028365\xb0028320\xc0000010 000037 00010
00015 000050 000123 00030 00079 101PC000'
解决方案
推荐阅读
- elasticsearch - 我正在尝试形成 Elasticsearch 查询。(SK=modelsku && DS=已批准)|| (DS=已批准 && RS = 已批准 && SK 以 sc 开头)以这种格式
- scalardl - Scalar DL 的资产记录如何避免 cosmosdb 的最大存储限制?
- sql - 为活动非活动输入数据填充 scd 类型 2 类型的日期
- python - 如何将 csv 文件的每一行转换为单独的文本文件?
- git - Visual Studio 2019 和 GIT - 更改分支后丢失引用
- multithreading - rust tui 应用程序中的并发 - 锁饥饿问题
- wordpress - 如何将在 wordpress.com 下开发的网站带到 hioxindia 托管帐户?
- python - 在 Python 中寻找高斯拟合的不确定性,减少卡方
- html - 最新的 Firefox 版本更改了网站布局
- c# - 调试 Nuget 包、dotnet Pack (.Net CLI) 与 Azure Pipeline Pack 任务