How to delete specific strings from a file?

后端 未结 5 2055
花落未央
花落未央 2020-12-02 01:22

I have a data file (unstructured, messy file) from which I have to scrub specific list of strings (delete strings).

Here is what I am doing but with no result:

5条回答
  •  半阙折子戏
    2020-12-02 01:40

    Maybe you can add encoding='utf-8' in your fin and fout variables. Here is the modified one you may want to use:

    fin=open(infile,"", encoding='utf-8')
    fout = open(outfile,"w+", encoding='utf-8')
    

    This(adding utf-8) mostly occurs on the OS Windows. Also for reading, writing, and appending the file, this usually isn't a problem but for advanced things to do a file like replacing text in there, etc then you should do this.

    Hope this helps you.

提交回复
热议问题