All Courses

Is there a way to see how much memory does a python module take?

By, a month ago
  • Bookmark

Can you determine the amount of memory consumed by a Python module?

Python module
Amount of memory consumed
1 Answer

Yes, there is a way to see how much memory a Python module is taking up. You can use the sys module and its getsizeof() function to get the size of any object in Python, including modules.

Here's an example:

import sys
import mymodule

size = sys.getsizeof(mymodule)
print("Size of mymodule: {} bytes".format(size))

In this example, mymodule is the name of the module you want to get the size of. The sys.getsizeof() function returns the size of the object in bytes. You can print out the size using the print() function.

Keep in mind that the size of a module may include the sizes of its imported modules as well, so the reported size may be larger than you expect.

Your Answer


Live Masterclass on : "How Machine Get Trained in Machine Learning?"

Mar 30th (7:00 PM) 516 Registered
More webinars

Related Discussions

Running random forest algorithm with one variable

View More