[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


[Advertise on 4chan]


What’s the proper way to measure your dict in bytes?

When you size up a dict, do you care more about how wide it is (number of entries) or how deep it goes (what each one holds)?

And when you need to unload the payload, do you dump it straight into a buffer, stream it somewhere else, or flush it to disk?
>>
>'ict in 'ytes
>>
>>107826742
db?
>>
>>107826703
python is not the right language to worry about memory usage
>>
>>107826703
>What’s the proper way to measure your dict in bytes?
write your Python in C using the extension API

like nigga wtf are you doing, you're in a duck typed garbage collected language
>dump straight into a buffer
no, you shouldn't pass arbitrary python objects around like a retard. the standard practice is to serialize them in some way. then you get a string or a buffer of specific length out, but at runtime the size of the object can vary hugely.
>>
File: 1767698396892044.gif (2.54 MB, 252x189)
2.54 MB
2.54 MB GIF
>>107826703
>the joke is sex
>>
>>107826703
len(json.dumps(mydict))
>>
File: apu_billiard.jpg (111 KB, 1024x702)
111 KB
111 KB JPG
>>107827256
>>107826742
oh fuck I fell for it
>>
>>107827267
>>> len(json.dumps(d))
Traceback (most recent call last):
File "<python-input-5>", line 1, in <module>
len(json.dumps(d))
~~~~~~~~~~^^^
File "/usr/lib/python3.13/json/__init__.py", line 235, in dumps
return _default_encoder.encode(obj)
~~~~~~~~~~~~~~~~~~~~~~~^^^^^
File "/usr/lib/python3.13/json/encoder.py", line 202, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.13/json/encoder.py", line 263, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python3.13/json/encoder.py", line 182, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
f'is not JSON serializable')



ok now what?
>>
>>107827256
thought we were having some sort of dict measuring contest here
>>
Nigga stole that joke from 10yo StackOverflow post, btw.
>>
>>107828593
it's new to me
>>
>>107826703
>I turned my dict into a pickle, Guido!
I'M PICKLED DICT!
>>
>>107826703
>MUH DICT



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.