How do I get Python to read and extract words from a text file?

This question already has an answer here:

  • How do I copy a file in python? 14 answers

  • A sample code to copy text from one file to another. Maybe it will help you:

    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/42328.html

    上一篇: 如何在Python中复制文件

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