{"id":116,"date":"2008-06-11T11:40:13","date_gmt":"2008-06-11T17:40:13","guid":{"rendered":"http:\/\/www.philhassey.com\/blog\/?p=116"},"modified":"2008-06-11T11:43:27","modified_gmt":"2008-06-11T17:43:27","slug":"learning-python-by-reinventing-wheels","status":"publish","type":"post","link":"https:\/\/www.philhassey.com\/blog\/2008\/06\/11\/learning-python-by-reinventing-wheels\/","title":{"rendered":"Learning python by reinventing wheels &#8230;"},"content":{"rendered":"<p>I&#8217;ve learned a lot about python by implementing <a href=\"http:\/\/www.tinypy.org\">tinypy<\/a>.  Today I was thinking over my <a href=\"http:\/\/groups.google.com\/group\/tinypy\/browse_thread\/thread\/6fffa1ceca14a3cf\">re-work of classes, objects, and inheritance<\/a> in tinypy (not in trunk yet).  I noted how in tinypy, I will be able to change the class of an object via a function call (a-la lua):<\/p>\n<p>class A: pass<br \/>\nclass B: pass<br \/>\nx = A() # x is an instance of A<br \/>\nsetmeta(x,B) # x is now an instance of B !!!<\/p>\n<p>So I thought to myself, I wonder if python can do that.  Well, it can, and as per usual, its solution is quite elegant:<\/p>\n<p>class A: pass<br \/>\nclass B: pass<br \/>\nx = A() # x is an instance of A<br \/>\nx.__class__ = B # x is now an instance of B !!!<\/p>\n<p>So, lesson of the day &#8212; you can dynamically change the class of an object in bigpy.  Which, actually, I&#8217;ve sometimes wanted to do, I just didn&#8217;t realize I *could* do it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve learned a lot about python by implementing tinypy. Today I was thinking over my re-work of classes, objects, and inheritance in tinypy (not in trunk yet). I noted how in tinypy, I will be able to change the class of an object via a function call (a-la lua): class A: pass class B: pass [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,2,32],"tags":[],"class_list":["post-116","post","type-post","status-publish","format-standard","hentry","category-crazy","category-python","category-tinypy"],"_links":{"self":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":0,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}