+-
如何在Python中确定“单词”大小
我需要知道 Python中’word’中的字节数.我需要这个的原因是我需要从文件中读取的单词数量;如果我知道单词中的字节数,我可以使用file.read(num_bytes)函数从文件中读取适当的数量.

如何确定单词中的字节数?

最佳答案
您可以使用 platform.architecture功能:

>>> import platform
>>> platform.architecture()
('64bit', '')

注意同一页面上的注释:

Note On Mac OS X (and perhaps other platforms), executable files may be universal files containing multiple architectures.
To get at the “64-bitness” of the current interpreter, it is more reliable to query the sys.maxsize attribute:

06001

请记住,这给出了编译python解释器的单词大小.如果在32位模式下编译python,则可以在64位主机上获得32的值.

如果文件是由其他可执行文件生成的,并且您可以访问此可执行文件,则可以使用platform.architecture函数的第一个可选参数:

>>> p.architecture('/path/to/executable')
('32bit', '')
点击查看更多相关文章

转载注明原文:如何在Python中确定“单词”大小 - 乐贴网