1

How to get str and dict size not length with python3.

My server get the data by json from a request. And I can dump the json. But I want to limit some specific fields' size. How can I do?

wyx
  • 3,334
  • 6
  • 24
  • 44
  • 2
    This [How do I determine the size of an object in Python?](http://stackoverflow.com/questions/449560/how-do-i-determine-the-size-of-an-object-in-python) – Moses Koledoye Aug 01 '16 at 07:53
  • So, just to be clear, neither strings nor dicts have length boundaries, are you asking how to add such features, so that they automatically truncate (or whatever) or how you can test whether certain strings or dict values exceed some limit? Or are you talking about the number of bytes the object takes up in memory? – jedwards Aug 01 '16 at 07:53
  • Bear in mind that the number of bytes a python object takes in memory is not necessarily the same as it would be when converted to JSON, which essentially is text. Some objects would be stored in binary (e.g. floats, ints) and might be larger as text. On the other hand Python objects have a degree of "red tape" management overhead not found in JSON. – cdarke Aug 01 '16 at 08:31

0 Answers0