{"id":654,"date":"2015-03-11T09:20:29","date_gmt":"2015-03-11T08:20:29","guid":{"rendered":"http:\/\/www.thelins.se\/johan\/blog\/?p=654"},"modified":"2015-03-11T10:32:01","modified_gmt":"2015-03-11T09:32:01","slug":"python-and-me","status":"publish","type":"post","link":"https:\/\/www.thelins.se\/johan\/blog\/2015\/03\/python-and-me\/","title":{"rendered":"Python and me"},"content":{"rendered":"<p>I like Python, but I&#8217;d love it if it had support for types &#8211; even if one of them was a generic duck-typed object or variant.<\/p>\n<p><code> x = {}<br \/>\nk = \"potential key\"<br \/>\nv = MyValue() # Clearly not a key<br \/>\n&nbsp;<br \/>\nif v in x:<br \/>\n&nbsp;&nbsp;pass # Always fails silently<br \/>\n&nbsp;<br \/>\n<\/code><\/p>\n<p>I apparently live and learn.<\/p>\n<p><em><strong>Update!<\/strong> Apparently I&#8217;m stupid while summarizing the error (always copy, never recall). I did not use <tt>k<\/tt> in the <tt>if<\/tt> statement, rather, I used <tt>v<\/tt> which is not a key. This is a programmer error. However, Python does not tell me so, it just does what it asks it to do, i.e. tell me if the not-a-key is a key.<\/p>\n<p>Thanks to Ralk for pointing this out.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I like Python, but I&#8217;d love it if it had support for types &#8211; even if one of them was a generic duck-typed object or variant. x = {} k = &#8220;potential key&#8221; v = MyValue() # Clearly not a key &nbsp; if v in x: &nbsp;&nbsp;pass # Always fails silently &nbsp; I apparently live &hellip; <a href=\"https:\/\/www.thelins.se\/johan\/blog\/2015\/03\/python-and-me\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Python and me<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-654","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/posts\/654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/comments?post=654"}],"version-history":[{"count":3,"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/posts\/654\/revisions"}],"predecessor-version":[{"id":657,"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/posts\/654\/revisions\/657"}],"wp:attachment":[{"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/media?parent=654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/categories?post=654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/tags?post=654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}