{"id":852,"date":"2019-08-11T07:15:31","date_gmt":"2019-08-11T07:15:31","guid":{"rendered":"http:\/\/shijuvarghese.com\/?p=852"},"modified":"2019-08-12T08:19:34","modified_gmt":"2019-08-12T08:19:34","slug":"python-file-handling-reading-file-line-by-line","status":"publish","type":"post","link":"http:\/\/shijuvarghese.com\/?p=852","title":{"rendered":"Python : File Handling &#8211; Reading file line by line"},"content":{"rendered":"<p>This post is a continuation of the post <a href=\"http:\/\/shijuvarghese.com\/?p=678\">Python : Basics of File Handling<\/a><\/p>\n<p>The below program prompts user to enter the full path of a file to be read, and prints each line one at a time, inserting a line of asterisks between each line.<\/p>\n<p>=== ===== ===<\/p>\n<p>#!\/usr\/bin\/python<\/p>\n<p>def theFile():<\/p>\n<p style=\"padding-left: 30px;\">print(&#8220;You have entered theFile function&#8221;)<br \/>\nfileSelection = raw_input(&#8220;Enter the file location :&#8221;)<br \/>\nprint(&#8220;The file you have selected is : &#8221; + str(fileSelection))<br \/>\ntheFile = open(fileSelection)<br \/>\ntheFileLines = theFile.readline()<\/p>\n<p style=\"padding-left: 30px;\">while theFileLines:<\/p>\n<p style=\"padding-left: 60px;\">print(theFileLines)<br \/>\nprint(&#8220;*********&#8221;)<br \/>\ntheFileLines=theFile.readline()<\/p>\n<p style=\"padding-left: 30px;\">theFile.close()<\/p>\n<p>theFile()<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>This post is a continuation of the post Python : Basics of File Handling The below program prompts user to enter the full path of <a class=\"mh-excerpt-more\" href=\"http:\/\/shijuvarghese.com\/?p=852\" title=\"Python : File Handling &#8211; Reading file line by line\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":518,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,22,27],"tags":[],"class_list":["post-852","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-programming","category-python"],"_links":{"self":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/852","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=852"}],"version-history":[{"count":8,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/852\/revisions"}],"predecessor-version":[{"id":860,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/852\/revisions\/860"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/media\/518"}],"wp:attachment":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=852"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}