{"id":39432,"date":"2016-11-26T23:36:31","date_gmt":"2016-11-27T05:36:31","guid":{"rendered":"http:\/\/welcometotheheaven.wordpress.com\/?p=680"},"modified":"2016-11-26T23:36:31","modified_gmt":"2016-11-27T05:36:31","slug":"writing-and-reading","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101fall2016\/syndicated\/writing-and-reading\/","title":{"rendered":"Writing and reading"},"content":{"rendered":"<p class=\"syndicated-attribution\"><em> --Originally published at <a href=\"https:\/\/welcometotheheaven.wordpress.com\/2016\/11\/27\/writing-and-reading\/\"><a href=\"https:\/\/welcometotheheaven.wordpress.com\">Welcome to the Heaven<\/a><\/a><\/em><br \/><\/p>\n<p>Writing and reading comments is pretty easy, we only need create a text file, open and select the mode that we will use.<\/p>\n<pre class=\"lang-py prettyprint prettyprinted\"><code><span class=\"typ\">Open()<\/span><\/code><\/pre>\n<p>First we need to create a variable with the code: example:<\/p>\n<p>text = open(file_name,mode)<\/p>\n<pre class=\"lang-py prettyprint prettyprinted\">Mode<\/pre>\n<p>Exist four kinds of modes: &#8220;r&#8221;, &#8220;w&#8221;, &#8220;a&#8221; and &#8220;r+&#8221;.<\/p>\n<p>&#8220;r&#8221;-&gt;Only for reading<\/p>\n<p>&#8220;w&#8221;-&gt;Writing(if you \u00a0have already a file with the same name will be erased)<\/p>\n<p>&#8220;a&#8221;-&gt;Open the file to append any type of data<\/p>\n<p>&#8220;r+&#8221;-&gt;Reading and Writing<\/p>\n<pre class=\"lang-py prettyprint prettyprinted\">Example<\/pre>\n<p>Writing<\/p>\n<p>I am going to use &#8220;shot&#8221;<br \/>\nas a name, and if you see the picture I don&#8217;t have any file with this name. So if you write the code of the next picture, your program is going to create a new\u00a0file with the name that you want and with the<br \/>\ntext that you write.\u00a0<img class=\" size-medium wp-image-699 aligncenter\" src=\"https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-29-46-pm.png?w=300&#038;h=144\" alt=\"screen-shot-2016-11-26-at-11-29-46-pm\" width=\"300\" height=\"144\" srcset=\"https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-29-46-pm.png?w=300&amp;h=144 300w, https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-29-46-pm.png?w=600&amp;h=288 600w, https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-29-46-pm.png?w=150&amp;h=72 150w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><img class=\" size-medium wp-image-706 aligncenter\" src=\"https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-34-37-pm.png?w=300&#038;h=113\" alt=\"screen-shot-2016-11-26-at-11-34-37-pm\" width=\"300\" height=\"113\" srcset=\"https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-34-37-pm.png?w=300&amp;h=113 300w, https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-34-37-pm.png?w=150&amp;h=56 150w, https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-34-37-pm.png 558w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>When you run your program in the terminal nothing is going to change, but if you search the file you will find it. Remember, if you have already a file with the same name will be erased.<img class=\" size-medium wp-image-715 aligncenter\" src=\"https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-39-21-pm.png?w=300&#038;h=159\" alt=\"screen-shot-2016-11-26-at-11-39-21-pm\" width=\"300\" height=\"159\" srcset=\"https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-39-21-pm.png?w=300&amp;h=159 300w, https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-39-21-pm.png?w=600&amp;h=318 600w, https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-39-21-pm.png?w=150&amp;h=79 150w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Reading<\/p>\n<p>I am going to use the file shot for the example.<img class=\" size-large wp-image-716 aligncenter\" src=\"https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-45-26-pm.png?w=820&#038;h=115\" alt=\"screen-shot-2016-11-26-at-11-45-26-pm\" srcset=\"https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-45-26-pm.png?w=150&amp;h=21 150w, https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-45-26-pm.png?w=300&amp;h=43 300w, https:\/\/welcometotheheaven.files.wordpress.com\/2016\/11\/screen-shot-2016-11-26-at-11-45-26-pm.png?w=768&amp;h=109 768w\" sizes=\"(max-width: 820px) 100vw, 820px\"   \/><\/p>\n<p>If you don&#8217;t write &#8220;()&#8221; at the final of file.read, when you run the program will print you the same as the first time.<\/p>\n<p><a href=\"http:\/\/www.pythonforbeginners.com\/files\/reading-and-writing-files-in-python\">More information and the source.<\/a><\/p><br \/>  <a rel=\"nofollow\" href=\"http:\/\/feeds.wordpress.com\/1.0\/gocomments\/welcometotheheaven.wordpress.com\/680\/\"><img alt=\"\" border=\"0\" src=\"http:\/\/feeds.wordpress.com\/1.0\/comments\/welcometotheheaven.wordpress.com\/680\/\" \/><\/a> <img alt=\"\" border=\"0\" src=\"https:\/\/pixel.wp.com\/b.gif?host=welcometotheheaven.wordpress.com&#038;blog=115373557&%23038;post=680&%23038;subd=welcometotheheaven&%23038;ref=&%23038;feed=1\" width=\"1\" height=\"1\" \/>","protected":false},"excerpt":{"rendered":"<p>&#8211;Originally published at Welcome to the Heaven Writing and reading comments is pretty easy, we only need create a text file, open and select the mode that we will use. Open() First we need to create a variable with the code: example: text = open(file_name,mode) Mode Exist four kinds of modes: &#8220;r&#8221;, &#8220;w&#8221;, &#8220;a&#8221; and &hellip; <a href=\"https:\/\/kenscourses.com\/tc101fall2016\/syndicated\/writing-and-reading\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Writing and reading<\/span><\/a><\/p>\n","protected":false},"author":32,"featured_media":699,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[24,33],"class_list":["post-39432","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogs","category-syndicated","tag-python","tag-tc101"],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/39432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/comments?post=39432"}],"version-history":[{"count":16,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/39432\/revisions"}],"predecessor-version":[{"id":43098,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/39432\/revisions\/43098"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/media?parent=39432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/categories?post=39432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/tags?post=39432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}