我试图在任何地方搜索,但找不到任何相关信息。

由于以下代码:

overlapped = pywintypes.OVERLAPPED()
buffer = win32file.AllocateReadBuffer(1024*4)
fullDataRead = []
hr, data = win32file.ReadFile(handle, buffer, overlapped)
n = win32file.GetOverlappedResult(handle, overlapped, 1)
read = str(data[:n])
fullDataRead.append(read)
print(fullDataRead)

我懂了
['<memory at 0x0000026821801348>']

但是我需要里面的字符串或字节。有什么想法如何读取memoryview对象吗?谢谢

最佳答案

可以使用memory.tobytes()对象转换为字符串,如下所示:

a = memoryview(b'mystring')
print(a)  # <memory at 0x10cbebb98>
print(a.tobytes())  # 'mystring'

关于python将memoryview转换为字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45455121/

10-12 16:48