4

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')
CDJB
  • 13,204
  • 5
  • 27
  • 47
Arya
  • 463
  • 4
  • 21

1 Answers1

3

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
CDJB
  • 13,204
  • 5
  • 27
  • 47
  • 1
    Thanks a lot for the reply.. May i know Is this size in KB or MB ? – Arya Dec 05 '19 at 16:13
  • 1
    It's in bytes, to convert that nicely into KB or MB or whatever, you could use one of the answers [here](https://stackoverflow.com/questions/5194057/better-way-to-convert-file-sizes-in-python/40347452). – CDJB Dec 05 '19 at 16:14