I need to write censor program that
1-reads in the text from a file
2-creates a new file where all the four-letter words have been replaced by “****”.
can you help? this what I have so far
import string
def main():
filename = raw_input("File: ")
text = open(filename,'r').read()
text = string.lower(text)
for ch in '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~':
text = string.replace(text, ch, ' ')
words = string.split(text)
wordCount = len(words)
ch = string.split(words)
charCount = len(ch)
if charCount == 4:
oldword = string.join(ch)
newtext = string.join(text)
o = open(filename,a)
for line in open(filename):
line = line.replace(oldword,newword)
o.write(line + "\n")
o.close()
text.close()
main()