{"id":125,"date":"2018-05-03T21:18:10","date_gmt":"2018-05-03T21:18:10","guid":{"rendered":"https:\/\/blog.johnny-lin.com\/?p=125"},"modified":"2018-05-03T21:19:11","modified_gmt":"2018-05-03T21:19:11","slug":"simple-conversions-from-python-2-7-to-python-3-x","status":"publish","type":"post","link":"https:\/\/blog.johnny-lin.com\/?p=125","title":{"rendered":"Simple Conversions from Python 2.7 to Python 3.x"},"content":{"rendered":"<p>Moving from Python 2.7 to 3.x is covered in much more detail <a href=\"https:\/\/docs.python.org\/3\/howto\/pyporting.html\">here<\/a>.  This list is just a list of items I&#8217;m checking as I make the switch.  It&#8217;s somewhat reflective of my own coding style and is meant more as a checklist for myself than anything, but if it helps you, great!<\/p>\n<ul>\n<li>Change <code>print<\/code> to <code>print()<\/code>.<\/li>\n<li>Change <code>xrange<\/code> to <code>range<\/code>.<\/li>\n<li>Change <code>raise, Execption \"Message\"<\/code> to <code>raise Exception(\"Message\")<\/code>.<\/li>\n<li>Change <code>from module import x<\/code> to <code>from .module import x<\/code>, if <code>module<\/code> is a relative import and not on the PYTHONPATH.  If I&#8217;m importing the entire module, it&#8217;s now <code>from . import module<\/code>.<\/li>\n<li>Anywhere there is integer division being used, change it from <code>\/<\/code> to <code>\/\/<\/code>.<\/li>\n<li>If I use the result of <code>range(...)<\/code> as a list, explicitly convert it to a list, e.g., <code>list(range(...))<\/code>.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Moving from Python 2.7 to 3.x is covered in much more detail here. This list is just a list of items I&#8217;m checking as I make the switch. It&#8217;s somewhat reflective of my own coding style and is meant more as a checklist for myself than anything, but if it helps you, great! Change print [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-125","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=125"}],"version-history":[{"count":2,"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":127,"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=\/wp\/v2\/posts\/125\/revisions\/127"}],"wp:attachment":[{"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.johnny-lin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}