I need to know the number of bytes in a ‘word’ in Python. The reason I need this is I have the number of words I need to read from a file; if I knew the number of bytes in a word, I can use the file.read(num_bytes) function to read the appropriate amount from the file.
How can I determine the number of bytes in a word?
You can use the
platform.architecturefunction:Pay attention to the note on the same page:
Please keep in mind that this gives the word size with which the python interpreter was compiled. You could obtain a value of 32 on a 64bit host if python was compiled in 32bit mode.
If the file is produced by a different executable and you have access to this executable, you can use the first optional argument to the
platform.architecturefunction: