How to determine 'word' size in Python

后端 未结 6 418
再見小時候
再見小時候 2021-01-20 00:03

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

6条回答
  •  遥遥无期
    2021-01-20 00:26

    How about something like this:

    def machine_word_size():
        import sys
        num_bytes = 0
        maxint = sys.maxint
        while maxint > 0:
            maxint = maxint >> 8
            num_bytes += 1
        return num_bytes
    

提交回复
热议问题