I tried to search everywhere but could not find any relevant info.
As a result of the following code:
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)
I get
['<memory at 0x0000026821801348>']
but I need strings or bytes that are inside. Any ideas how to read a memoryview
object? Thank you
A memory
object can be converted to a string using .tobytes()
like so:
a = memoryview(b'mystring')
print(a) # <memory at 0x10cbebb98>
print(a.tobytes()) # 'mystring'
For Python 2.7 and 3.x you can try this:
a = memoryview(b'mystring')
print(a) # <memory at 0x10cbebb98>
#for string
print(str(a,'utf8')) # 'mystring' as UTF-8
# for bytes
print(bytes(a)) # b'mystring'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With