1
path = "c:\\temp\\mypythonfiles\\plague_warning.txt"
txt = open(path, "r+")

for line in txt:
    print(line)

txt.write("The Black Death was one of the most devastating\n")
txt.write("pandemics in human history, resulting in the deaths\n")
txt.write("of an estimated 75 to 200 million people and peaking\n")
txt.write("in Europe in the years 1346–53. Although there were\n")
txt.write("several competing theories as to the etiology of the\n")
txt.write("Black Death, analysis of DNA from victims in northern\n")
txt.write("and southern Europe published in 2010 and 2011 indicates\n")
txt.write("that the pathogen responsible was the Yersinia pestis\n")
txt.write("bacterium, probably causing several forms of plague.\n")

txt.close()


path = "c:\\temp\\mypythonfiles\\plague_warning.txt"
txt = open(path, "r")


for line in txt:
    print(line)

txt.close()

The original .txt document is displayed properly and the new lines are properly appended to the document. Below is the error I receive after the script displays the first few lines of the appended document. It displays it up through the third line of newly written text, to the word peaking.

Traceback (most recent call last): File "e:\pythonscripts\Lesson12_2.py", line 45, in print(line) File "C:\Python34\lib\encodings\cp437.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u2013' in position 27: character maps to

0 Answers0