text: Q:
  
  How to Print a string to a specific character?
  
  I have a file like this:
  NA|polymerase|KC545393|Bundibugyo_ebolavirus|EboBund_112_2012|NA|2012|Human|Democratic_Republic_of_the_Congo
  NA|VP24|KC545393|Bundibugyo_ebolavirus|EboBund_112_2012|NA|2012|Human|Democratic_Republic_of_the_Congo
  NA|VP30|KC545393|Bundibugyo_ebolavirus|EboBund_112_2012|NA|2012|Human|Democratic_Republic_of_the_Congo
  
  I am trying to print this characters from each line:
  polymerase|KC545393
  VP24|KC545393
  VP30|KC545393
  
  How can I do this?
  I tried this code:
  for character in line:
      if character=="|":
          print line[1:i.index(j)]
  
  A:
  
  Use str.split() to split each line by the '|' character; you can limit the splitting because you only need the first 3 columns:
  elems = line.split('|', 3)
  print '|'.join(elems[1:3])
  
  The print line then takes the elements at index 1 and 2 and joins them together again using the '|' character to produce your desired output.
  Demo:
  >>> lines = '''\
  ... NA|polymerase|KC545393|Bundibugyo_ebolavirus|EboBund_112_2012|NA|2012|Human|Democratic_Republic_of_the_Congo
  ... NA|VP24|KC545393|Bundibugyo_ebolavirus|EboBund_112_2012|NA|2012|Human|Democratic_Republic_of_the_Congo
  ... NA|VP30|KC545393|Bundibugyo_ebolavirus|EboBund_112_2012|NA|2012|Human|Democratic_Republic_of_the_Congo
  ... '''.splitlines(True)
  >>> for line in lines:
  ...     elems = line.split('|', 3)
  ...     print '|'.join(elems[1:3])
  ... 
  polymerase|KC545393
  VP24|KC545393
  VP30|KC545393
  
  