The title says it all. I know pickle can do it, but I don't really want to open a file just to convert a single number. I want to take float('nan') and send it over the network in its binary format.
>>> import struct
>>> struct.pack('d', float('nan'))
b'\x00\x00\x00\x00\x00\x00\xf8\x7f'
if you want a double-precision (8-byte) binary representation in little-endian format. See https://docs.python.org/2/library/struct.html for all details of how to use big-endian and/or single-precision (4-byte) format instead.
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