size of object

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
philwilkinson40
Posts: 63
Joined: Tue Nov 14, 2017 3:11 am
Location: Perth, Australia

size of object

Post by philwilkinson40 » Sun Mar 10, 2019 12:59 am

Is there an equivalent of sys.getsizeof() in micropython?

I am looking to check the size of various objects prior to sending data across a LPWAN from a remote IOT device. If the size is too large I may split the data or save to a local SD card.

If this is not implemented, is there a way I can obtain the size at a point where I ustruct.pack() ??

sorry for the basic python primitives question... :oops:

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: size of object

Post by dhylands » Sun Mar 10, 2019 1:13 am

You can use struct.calcsize(fmt) to determine how much data will be needed to store a given fmt string. This is the same fmt string that is passed to struct.pack

Post Reply