line = line.rstrip('\n') is a simpler way to do this.