{"id":15460,"date":"2016-07-29T14:12:55","date_gmt":"2016-07-29T18:12:55","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=15460"},"modified":"2016-07-29T14:12:55","modified_gmt":"2016-07-29T18:12:55","slug":"python-internals-pyobject","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/07\/29\/python-internals-pyobject\/","title":{"rendered":"Python Internals: PyObject"},"content":{"rendered":"<p><a href=\"http:\/\/www.gahcep.com\/python-internals-pyobject\/\">Sergei Danielian<\/a> (via <a href=\"https:\/\/news.ycombinator.com\/item?id=12180301\">Hacker News<\/a>):<\/p>\n<blockquote cite=\"http:\/\/www.gahcep.com\/python-internals-pyobject\/\"><p>Each Python&rsquo;s type implementation (<code>PyIntObject<\/code>, <code>PyFloatObject<\/code> or <code>PyDictObject<\/code>) has <code>PyObject_HEAD<\/code> located as its first member (or the first member of its first member, and so on). This member sub-object is guaranteed to be located at the same address as the full object.<\/p>\n<p>The <code>PyObject_HEAD<\/code> refers at that member sub-object, but could be cast to the full type once <code>ob_type<\/code> has been inspected to get knowledge of what the full type is.<\/p><\/blockquote>\n\n<p><a href=\"http:\/\/pgbovine.net\/cpython-internals.htm\">Philip Guo<\/a>:<\/p>\n<blockquote cite=\"http:\/\/pgbovine.net\/cpython-internals.htm\"><p>Here are nine lectures walking through the internals of CPython, the canonical Python interpreter implemented in C. They were from a dynamic programming languages course that I taught in Fall 2014 at the University of Rochester. The format isn&rsquo;t ideal, but I haven&rsquo;t seen this level of detail about CPython presented online, so I wanted to share these videos.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/jakevdp.github.io\/blog\/2014\/05\/09\/why-python-is-slow\/\">Jake Vanderplas<\/a>:<\/p>\n<blockquote cite=\"https:\/\/jakevdp.github.io\/blog\/2014\/05\/09\/why-python-is-slow\/\"><p>We saw above the extra type info layer when moving from a C integer to a Python integer. Now imagine you have many such integers and want to do some sort of batch operation on them. In Python you might use the standard <code>List<\/code> object, while in C you would likely use some sort of buffer-based array.<\/p>\n<p>A NumPy array in its simplest form is a Python object build around a C array. That is, it has a pointer to a <em>contiguous<\/em> data buffer of values. A Python list, on the other hand, has a pointer to a contiguous buffer of pointers, each of which points to a Python object which in turn has references to its data (in this case, integers).<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Sergei Danielian (via Hacker News): Each Python&rsquo;s type implementation (PyIntObject, PyFloatObject or PyDictObject) has PyObject_HEAD located as its first member (or the first member of its first member, and so on). This member sub-object is guaranteed to be located at the same address as the full object. The PyObject_HEAD refers at that member sub-object, but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[45,46,71,232],"class_list":["post-15460","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-c","tag-languagedesign","tag-programming","tag-python"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/15460","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=15460"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/15460\/revisions"}],"predecessor-version":[{"id":15461,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/15460\/revisions\/15461"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=15460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=15460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=15460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}