0

I have a txt file to which i want to split on the basis of new line. i write code then find error in it and help me. code is

 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

my file looks like this:

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
Shaheen Gul
  • 61
  • 2
  • 4
  • 10

1 Answers1

2

try like this:

with open("C:/Python26/trigram.txt") as f:
    my_list = f.readlines()
    for x in my_list:
        print x

OR

with open("C:/Python26/trigram.txt") as f:
    for lines in f:
        print lines
Hackaholic
  • 19,069
  • 5
  • 54
  • 72
  • 1
    @ShaheenGul dont edit the post when it answered, else now my answer is wrong for ur edit, you can start a new post – Hackaholic Apr 04 '15 at 04:06