Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the size of a set variable in Python?

I have code as below where table data is captured in set(cur). Is there any way to find the space occupied by this variable in linux/unix? (Memory or buffer space)

cur.execute("select A , B , C from DeptTable")
dept_entries = set(cur)

cur.execute("select A , B , C from EmployeeTable where EmplName in ('A','B')") 
for empl in cur:
  if empl in dept_entries:
    print(empl, 'Yes')
  else:
    print(empl, 'No')
like image 563
Arya Avatar asked Oct 16 '25 14:10

Arya


1 Answers

I would recommend using sys.getsizeof:

>>> import sys
>>> sys.getsizeof(dept_entries)
12345
>>> sys.getsizeof(set([1,2,3]))
224
>>> sys.getsizeof(set([1,2,3,4,5]))
736
like image 172
CDJB Avatar answered Oct 18 '25 03:10

CDJB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!