Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Read Square Eared Story
- file = open("henryTheSquareEaredCat.txt", 'r')
- #for line in file:
- #print(line, end="")
- #file.close()
- #Write Pentagon Eared Story
- file = open("henryTheSquareEaredCat.txt", 'r')
- newLines = ['Pentagon', 'pentagon']
- for line in file:
- if ['Square', 'square'] in line:
- newLine = line.replace(['Square', 'Pentagon'], ['square', 'pentagon'])
- newLines.append(newLine)
- else:
- newLines.append(line)
- file.close()
- print(newLines)
- with open("henryThePentagonEaredCat.txt", 'w') as newFile:
- for newLine in newLines:
- newFile.write(newLine)
- newFile.close()
- #Verify new file exists
- import os
- if os.path.exists("henryThePentagonEaredCat.txt"):
- print("Nailed It!")
- else:
- print("Did NOT nail it")
Add Comment
Please, Sign In to add comment