Home > Back-end >  How to convert result from win32file.ReadFile to something readable?
How to convert result from win32file.ReadFile to something readable?

Time:02-10

I made a named pipe and its working fine: the client is writing to it and the server is receiving it.

How do I convert a PyOVERLAPPEDReadBuffer object to the actual data that I want? Im passing a double with size of 8 (i think).

The docs im using: http://timgolden.me.uk/pywin32-docs/win32file__ReadFile_meth.html

hr, thing = win32file.ReadFile(pipe, 8)
print("hr: "   str(hr))
print("thing: "   str(thing))

output

hr: 0
thing: b'\xbc\x91y\xe4\x0f\x06\xeb?'

CodePudding user response:

In case thing is Bytes and you expect a double, you could use struct.unpack to convert:

>>> thing = b'\xbc\x91y\xe4\x0f\x06\xeb?'
>>> import struct
>>> d, = struct.unpack('d', thing)
>>> d
0.84449
  • Related