{"id":3292,"date":"2012-10-04T22:12:07","date_gmt":"2012-10-04T21:12:07","guid":{"rendered":"http:\/\/emilkirkegaard.dk\/en\/?p=3292"},"modified":"2012-10-04T22:12:07","modified_gmt":"2012-10-04T21:12:07","slug":"review-of-python-book-and-some-other-thoughts","status":"publish","type":"post","link":"https:\/\/emilkirkegaard.dk\/en\/2012\/10\/review-of-python-book-and-some-other-thoughts\/","title":{"rendered":"Review of python book and some other thoughts"},"content":{"rendered":"<p><a href=\"http:\/\/www.techdirt.com\/articles\/20120923\/22351120487\/googles-copyright-crackdown-punishes-author-torrenting-his-own-book.shtml\">It was mentioned by TechDirt<\/a> in their reporting on an absurd copyright case (so, pretty normal).<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>The strange choice of the author to use identation to mark borders between paragrafs when indents are very important in python. He cud just have used newlines to do that.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>The code is not easily copyable. If one tries, one gets spaces between every character or so like this: &gt;&gt;&gt;cho i c e = \u2019ham\u2019. This seems to be due to the font used.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Sometimes the examples are not clearly enuf explained. For instance, elif is explained as an \u201coptional condition\u201d, which is not all that clear. Fortunately, this is not much of a problem if one has an IDE ready to test it. For the record, elif works as an alternative condition if the first one isnt true. Ex.:<\/p>\n<p><span style=\"font-family: Courier New,monospace;\">a = 1<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">b = 2<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">c = 3<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">if a == 1:<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">print &#8220;a holds&#8221;<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">elif b == 2:<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">print &#8220;b holds and a doesnt&#8221;<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">elif c == c:<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">print &#8220;neither a or b holds, but c does&#8221;<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">&gt;&gt;a holds<\/span><\/p>\n<p>and:<\/p>\n<p><span style=\"font-family: Courier New,monospace;\">a = 0<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">b = 2<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">c = 3<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">if a == 1:<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">print &#8220;a holds&#8221;<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">elif b == 2:<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">print &#8220;b holds and a doesnt&#8221;<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">elif c == c:<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">print &#8220;neither a or b holds, but c does&#8221;<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">&gt;&gt;b holds and a doesnt<\/span><\/p>\n<p>lastly:<\/p>\n<p><span style=\"font-family: Courier New,monospace;\">a = 0<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">b = 4<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">c = 3<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">if a == 1:<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">print &#8220;a holds&#8221;<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">elif b == 2:<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">print &#8220;b holds and a doesnt&#8221;<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">elif c == c:<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">print &#8220;neither a or b holds, but c does&#8221;<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">&gt;&gt;neither a or b holds, but c does<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>Note how the order of the elif&#8217;s matter. An elif only activates when all the previous if&#8217;s and elif&#8217;s failed.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Python apparently does not understand how to add numbers and strings. So things like:<\/p>\n<p><span style=\"font-family: Courier New,monospace;\">a = &#8220;string&#8221;<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">b = 1<\/span><\/p>\n<p><span style=\"font-family: Courier New,monospace;\">print a+b<\/span><\/p>\n<p>gives an error. It seems to me that one shud just have python autoconvert numbers to strings (using str function), just as python converts integers to floats when adding such two objects together. Perhaps this has changed in python 3ff. Im running 2.7.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It was mentioned by TechDirt in their reporting on an absurd copyright case (so, pretty normal). &nbsp; &nbsp; The strange choice of the author to use identation to mark borders between paragrafs when indents are very important in python. He cud just have used newlines to do that. &nbsp; &nbsp; The code is not easily [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[1931],"class_list":["post-3292","post","type-post","status-publish","format-standard","hentry","tag-programming","entry"],"_links":{"self":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/3292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/comments?post=3292"}],"version-history":[{"count":2,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/3292\/revisions"}],"predecessor-version":[{"id":3356,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/3292\/revisions\/3356"}],"wp:attachment":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/media?parent=3292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/categories?post=3292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/tags?post=3292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}