{"id":4552,"date":"2023-12-15T15:49:23","date_gmt":"2023-12-15T15:49:23","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4552"},"modified":"2023-12-15T15:49:34","modified_gmt":"2023-12-15T15:49:34","slug":"read-file","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/file-input-and-output\/read-file","title":{"rendered":"Read File"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Read a line from a text file example<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>    with open(\"ap_defines.DIRECTORY_FILES_ROOT + ap_defines.DIRECTORY_FILES_DATABASE\"my_file.txt\") as file1:\r\n        line = file1.readline()\r\n        if 'some_value' in line:    #Does line contain \"some_value:\"\n            some_value = line.split(\":\")&#91;-1].strip()    #Get the value after the ':'\r\n            print (\"some_value: \" + some_value)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Read a line from a text file example<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[344],"tags":[],"class_list":["post-4552","post","type-post","status-publish","format-standard","hentry","category-file-input-and-output"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4552"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4552\/revisions"}],"predecessor-version":[{"id":4554,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4552\/revisions\/4554"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}