Python . How to get rid of '\r' in string?

Posted by draconisthe0ry on Stack Overflow See other posts from Stack Overflow or by draconisthe0ry
Published on 2012-12-01T05:01:17Z Indexed on 2012/12/01 5:03 UTC
Read the original article Hit count: 52

Filed under:
|
|
|
|

I have an excel file that I converted to a text file with a list of numbers.

test = 'filelocation.txt'

in_file = open(test,'r')

for line in in_file:
    print line

1.026106236
1.660274766
2.686381002
4.346655769
7.033036771
1.137969254

a = []

for line in in_file:
    a.append(line) print a

'1.026106236\r1.660274766\r2.686381002\r4.346655769\r7.033036771\r1.137969254'

I wanted to assign each value (in each line) to an individual element in the list. Instead it is creating one element separated by \r . i'm not sure what \r is but why is putting these into the code ?

I think I know a way to get rid of the \r from the string but i want to fix the problem from the source

© Stack Overflow or respective owner

Related posts about python

Related posts about string