{"id":1286,"date":"2011-12-02T13:40:57","date_gmt":"2011-12-02T18:40:57","guid":{"rendered":"http:\/\/cd34.com\/blog\/?p=1286"},"modified":"2011-12-02T15:32:14","modified_gmt":"2011-12-02T20:32:14","slug":"python-coding-standards-for-imports","status":"publish","type":"post","link":"https:\/\/cd34.com\/blog\/programming\/python\/python-coding-standards-for-imports\/","title":{"rendered":"Python coding standards for imports"},"content":{"rendered":"<p>Recently I&#8217;ve been refactoring a lot of code and I&#8217;m seeing a few trends that I find easier to read.<\/p>\n<p>With imports, I prefer putting each import on its own line. It takes up more screenspace, but, when looking at a commit diff, I can see what was added or removed much more easily than a string changed in the middle (though, more of the diff tools are showing inline differences).<\/p>\n<p>However, what I started to do recently was do imports like:<\/p>\n<pre>\r\nfrom module import blah, \\\r\n                   blah2, \\\r\n                   blah3\r\n<\/pre>\n<p>I keep them in alphabetical order, but, I find that reading through that removes the &#8216;wall of text&#8217; effect.<\/p>\n<p>Original imports:<\/p>\n<pre>\r\nfrom module import blah\r\nfrom module import blah2\r\nfrom module import blah3\r\n<\/pre>\n<p>I find that the new method I&#8217;m using allows me to more easily see that two imports came from the same module.<\/p>\n<p>Another possibility as mentioned by Chris McDonough is:<\/p>\n<pre>\r\nfrom module import (blah,\r\n                    blah2,\r\n                    blah3)\r\n<\/pre>\n<div style=\"float:left;\">\n<div id=\"fb-root\"><\/div>\n<fb:like href=\"https:\/\/cd34.com\/blog\/programming\/python\/python-coding-standards-for-imports\/\" width=\"250\" send=\"false\" show_faces=\"false\" layout=\"button_count\" action=\"recommend\"><\/fb:like>\n<\/div><div style=\"clear:both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Recently I&#8217;ve been refactoring a lot of code and I&#8217;m seeing a few trends that I find easier to read. With imports, I prefer putting each import on its own line. It takes up more screenspace, but, when looking at a commit diff, I can see what was added or removed much more easily than [&hellip;]<\/p>\n<div style=\"float:left;\">\n<div id=\"fb-root\"><\/div>\n<fb:like href=\"https:\/\/cd34.com\/blog\/programming\/python\/python-coding-standards-for-imports\/\" width=\"250\" send=\"false\" show_faces=\"false\" layout=\"button_count\" action=\"recommend\"><\/fb:like>\n<\/div><div style=\"clear:both;\"><\/div>","protected":false},"author":15,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[211,210],"class_list":["post-1286","post","type-post","status-publish","format-standard","hentry","category-python","tag-imports","tag-pep8"],"_links":{"self":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/comments?post=1286"}],"version-history":[{"count":3,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1286\/revisions"}],"predecessor-version":[{"id":1288,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1286\/revisions\/1288"}],"wp:attachment":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/media?parent=1286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/categories?post=1286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/tags?post=1286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}