根据redditmetrics.com,Reddit上有超过一百万个子评价.
我写了一个脚本,反复查询this Reddit API endpoint,直到所有的subreddits都存储在一个数组all_subs中:
all_subs = []
for sub in :
all_subs.append({"name": display_name, "subscribers": subscriber_count})
该脚本已经运行了近十个小时,大约已经完成了一半(每三个或四个请求就会受到速率限制).当它完成后,我期待一个像这样的数组:
[
{ "name": "AskReddit", "subscribers", 16751677 },
{ "name": "news", "subscribers", 13860169 },
{ "name": "politics", "subscribers", 3350326 },
... # plus one million more entries
]
这个列表占用的内存空间大约是多少?
解决方法:
这取决于你的Python版本和你的系统,但我会帮你弄清楚它需要多少内存.首先,sys.getsizeof只返回表示容器的对象的内存使用,而不是容器中的所有元素.
Only the memory consumption directly attributed to the object is
accounted for, not the memory consumption of objects it refers to.
If given