pythonjython

Jython: How to remove '\n' from the end of a string being read in


Possible Duplicate:
Python: How to remove /n from a list element?

I'm trying to read in data from text file but when the data is read in and added to an array, so is the '\n' because each set of data is on a new line.

  for j in range(numStations):
    allStations.insert(j, my_file2.readline())

Which results in an output of:

  ['H1\n', 'H2\n', 'H3\n', 'H4\n', 'H5\n', 'Harriston\n']

Solution

  • Did you try the normal way of getting rid of whitespace?

    my_file2.readline().strip()