{"id":253,"date":"2022-05-24T15:18:17","date_gmt":"2022-05-24T14:18:17","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/?page_id=253"},"modified":"2022-05-24T17:31:13","modified_gmt":"2022-05-24T16:31:13","slug":"file-handling","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/file-handling\/","title":{"rendered":"File Handling"},"content":{"rendered":"<p>When programming, it is useful to be able to work with files and data that is <b>stored out with the code<\/b>\u00a0in an <strong>external file<\/strong>. This can be very useful when you want to <strong>import <\/strong>a large amount of information into the program rather than having to type it in manually. This can also be beneficial if you would like to <strong>export data <\/strong>from a program so it can be used again in the future.<\/p>\n<h2 style=\"color: red\">Read From File<\/h2>\n<p data-reactid=\".22usob1jq1k.0.0.0.1:0.1.0.$0.$2.$14\"><span data-reactid=\".22usob1jq1k.0.0.0.1:0.1.0.$0.$2.$14.0\">To Read from a sequential file means to take the data from the file and store it in a variable, array or record for future use in the program.<\/span><\/p>\n<p data-reactid=\".22usob1jq1k.0.0.0.1:0.1.0.$0.$2.$15\"><span data-reactid=\".22usob1jq1k.0.0.0.1:0.1.0.$0.$2.$15.0\">Before you can read from a file you have to open the file. Once the file is open it is possible to create code that will read specific data from the file.<\/span><\/p>\n<p data-reactid=\".22usob1jq1k.0.0.0.1:0.1.0.$0.$2.$15\"><strong style=\"color: red\">Example in Python<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-255\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24151756\/Screenshot-2022-05-24-151721-300x168.png\" alt=\"\" width=\"764\" height=\"428\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24151756\/Screenshot-2022-05-24-151721-300x168.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24151756\/Screenshot-2022-05-24-151721-624x349.png 624w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24151756\/Screenshot-2022-05-24-151721.png 707w\" sizes=\"auto, (max-width: 764px) 100vw, 764px\" \/><\/p>\n<p><strong style=\"color: red\">Example in Pseudocode<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-257\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24153342\/Screenshot-2022-05-24-153249-300x211.png\" alt=\"\" width=\"470\" height=\"331\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24153342\/Screenshot-2022-05-24-153249-300x211.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24153342\/Screenshot-2022-05-24-153249.png 378w\" sizes=\"auto, (max-width: 470px) 100vw, 470px\" \/><\/p>\n<h2 style=\"color: red\">Write to File<\/h2>\n<p>When you write to a file you are often sending the values held in variables, arrays and records out of the program for storage within a sequential file.<\/p>\n<p><strong style=\"color: red\">Example in Python<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-260\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24154216\/Screenshot-2022-05-24-154117-300x65.png\" alt=\"\" width=\"739\" height=\"160\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24154216\/Screenshot-2022-05-24-154117-300x65.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24154216\/Screenshot-2022-05-24-154117-768x166.png 768w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24154216\/Screenshot-2022-05-24-154117-624x135.png 624w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24154216\/Screenshot-2022-05-24-154117.png 931w\" sizes=\"auto, (max-width: 739px) 100vw, 739px\" \/><\/p>\n<p><strong style=\"color: red\">Example in Pseudocode<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-262\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24173106\/Screenshot-2022-05-24-173051-300x99.png\" alt=\"\" width=\"445\" height=\"147\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24173106\/Screenshot-2022-05-24-173051-300x99.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24173106\/Screenshot-2022-05-24-173051-624x205.png 624w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phshighercomputingscience\/uploads\/sites\/10042\/2022\/05\/24173106\/Screenshot-2022-05-24-173051.png 706w\" sizes=\"auto, (max-width: 445px) 100vw, 445px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When programming, it is useful to be able to work with files and data that is stored out with the code\u00a0in an external file. This can be very useful when you want to import a large amount of information into the program rather than having to type it in manually. This can also be beneficial [&hellip;]<\/p>\n","protected":false},"author":79984,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-253","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/pages\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/users\/79984"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":5,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/pages\/253\/revisions"}],"predecessor-version":[{"id":263,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/pages\/253\/revisions\/263"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phshighercomputingscience\/wp-json\/wp\/v2\/media?parent=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}