{"id":65399,"date":"2016-09-02T10:05:18","date_gmt":"2016-09-02T18:05:18","guid":{"rendered":"http:\/\/www.transterrestrial.com\/?p=65399"},"modified":"2016-09-02T10:05:18","modified_gmt":"2016-09-02T18:05:18","slug":"python-problem","status":"publish","type":"post","link":"https:\/\/www.transterrestrial.com\/wordpress\/2016\/09\/02\/python-problem\/","title":{"rendered":"Python Problem"},"content":{"rendered":"<p>Anyone have any idea why the following script doesn&#8217;t work?<\/p>\n<p>*************************************<br \/>\n#!\/usr\/bin\/env python3<\/p>\n<p># import modules used here &#8212; sys is a very standard one<br \/>\nimport sys<br \/>\n#import re<\/p>\n<p># Gather our code in a main() function<br \/>\ndef main():<br \/>\n    infile = open(&#8216;File1&#8217;, &#8216;r&#8217;)<br \/>\n    outfile = open(&#8216;File2&#8217;, &#8216;w&#8217;)<br \/>\n    for line in infile:<br \/>\n        line.replace(&#8220;<\/p>\n<p class=\\\"P1\\\">\n<p>&#8220;,&#8221;test&#8221;)<br \/>\n            #print(&#8220;Found string&#8221;)<br \/>\n        outfile.write(line)<\/p>\n<p># Standard boilerplate to call the main() function to begin<br \/>\n# the program.<br \/>\nif __name__ == &#8216;__main__&#8217;:<br \/>\n    main()<br \/>\n*************************************<\/p>\n<p>When I run it, it simply copies the old file to the new one, without doing the replacement. I know that it&#8217;s seeing the pattern, because if I run the replace function in an if statement, it says that it found it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Anyone have any idea why the following script doesn&#8217;t work? ************************************* #!\/usr\/bin\/env python3 # import modules used here &#8212; sys is a very standard one import sys #import re # Gather our code in a main() function def main(): infile = open(&#8216;File1&#8217;, &#8216;r&#8217;) outfile = open(&#8216;File2&#8217;, &#8216;w&#8217;) for line in infile: line.replace(&#8220; &#8220;,&#8221;test&#8221;) #print(&#8220;Found string&#8221;) &hellip; <a href=\"https:\/\/www.transterrestrial.com\/wordpress\/2016\/09\/02\/python-problem\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Python Problem<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,3],"tags":[],"class_list":["post-65399","post","type-post","status-publish","format-standard","hentry","category-administrative","category-technology-and-society"],"_links":{"self":[{"href":"https:\/\/www.transterrestrial.com\/wordpress\/wp-json\/wp\/v2\/posts\/65399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.transterrestrial.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.transterrestrial.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.transterrestrial.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.transterrestrial.com\/wordpress\/wp-json\/wp\/v2\/comments?post=65399"}],"version-history":[{"count":1,"href":"https:\/\/www.transterrestrial.com\/wordpress\/wp-json\/wp\/v2\/posts\/65399\/revisions"}],"predecessor-version":[{"id":65400,"href":"https:\/\/www.transterrestrial.com\/wordpress\/wp-json\/wp\/v2\/posts\/65399\/revisions\/65400"}],"wp:attachment":[{"href":"https:\/\/www.transterrestrial.com\/wordpress\/wp-json\/wp\/v2\/media?parent=65399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.transterrestrial.com\/wordpress\/wp-json\/wp\/v2\/categories?post=65399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.transterrestrial.com\/wordpress\/wp-json\/wp\/v2\/tags?post=65399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}