python编程快速上手第8章实践项目疯狂填词

import re
oldFile=open('C:/Users/Administrator/Desktop/test.txt')
newFile=open('C:/Users/Administrator/Desktop/test2.txt','w')
oldFileContent=oldFile.read()

tempFileContent=re.sub(r'[^a-zA-Z,\s]',"  .",oldFileContent)
print(tempFileContent)
tempFileList=tempFileContent.split(" ")
print(tempFileList)
keyWords=['ADJECTIVE','NOUN','ADVERB','VERB']
for i in range(len(tempFileList)):
    for j in range(len(keyWords)):             
        if(tempFileList[i] == keyWords[j]):
            print('Enter an '+keyWords[j]+':')
            tempFileList[i] = input()

newFileContent=' '.join(tempFileList).replace("  .",".")

print(newFileContent)
newFile.write(newFileContent)
oldFile.close()
newFile.close()

 

你可能感兴趣的:(python编程快速上手)