如何确定Python中对象的大小?

自作多情 提交于 2020-08-17 06:00:27

问题:

In C, we can find the size of an int , char , etc. I want to know how to get size of objects like a string, integer, etc. in Python. 在C语言中,我们可以找到intchar等的大小。我想知道如何在Python中获取对象的大小,例如字符串,整数等。

Related question: How many bytes per element are there in a Python list (tuple)? 相关问题: Python列表(元组)中每个元素有多少个字节?

I am using an XML file which contains size fields that specify the size of value. 我使用的XML文件包含指定值大小的大小字段。 I must parse this XML and do my coding. 我必须解析此XML并进行编码。 When I want to change the value of a particular field, I will check the size field of that value. 当我想更改特定字段的值时,我将检查该值的大小字段。 Here I want to compare whether the new value that I'm gong to enter is of the same size as in XML. 在这里,我想比较输入的新值是否与XML中的值相同。 I need to check the size of new value. 我需要检查新值的大小。 In case of a string I can say its the length. 如果是字符串,我可以说它的长度。 But in case of int, float, etc. I am confused. 但是如果是int,float等,我会感到困惑。


解决方案:

参考一: https://stackoom.com/question/1swy/如何确定Python中对象的大小
参考二: https://oldbug.net/q/1swy/How-do-I-determine-the-size-of-an-object-in-Python
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!