如何让Python从文本文件中读取和提取单词?

这个问题在这里已经有了答案:

  • 如何在python中复制文件? 14个答案

  • 将文本从一个文件复制到另一个文件的示例代码。 也许它会帮助你:

    inputFile = open("Input.txt","r")
    text = inputFile.read()
    inputFile.close()
    outputFile = open("Output.txt","w")
    outputFile.write(text)
    outputFile.close()
    

    简单的就试试这个

    #open input file and read all lines and save it in a list
    fin = open("Input.txt","r")
    f = fin.readlines()
    fin.close()
    
    #open output file and write all lines in it
    fout = open("Output.txt","wt")
    for i in f:
        fout.write(i)
    fout.close()
    
    链接地址: http://www.djcxy.com/p/42327.html

    上一篇: How do I get Python to read and extract words from a text file?

    下一篇: How to get python to copy files to desktop