how to split file on every new line in python
本问题已经有最佳答案,请猛点这里访问。
我有一个txt文件,我想在新行的基础上拆分到该文件。我编写代码,然后在其中发现错误并帮助我。代码是
1 2 3 4 5 6 7 | file = open("C:/Python26/trigram.txt"); f = open("Prefix.txt",'w'); f_up = open("Prefix.txt",'w'); contents=file.read(); tokens = nltk.word_tokenize(contents); for t in tokens: print t |
我的文件如下:
1 2 3 4 5 6 | IL-2$gene$expression$and IL-2$gene$expression$and$NF-kappa IL-2$gene$expression$and$NF-kappa$B IL-2$gene$expression$and$NF-kappa$B$activation gene$expression$and$NF-kappa$B$activation$through expression$and$NF-kappa$B$activation$through$CD28 |
试试这个
1 2 3 4 | with open("C:/Python26/trigram.txt") as f: my_list = f.readlines() for x in my_list: print x |
黄金
ZZU1