Richard
Richard

Reputation: 15902

strip spaces in python

ok I know that this should be simple... anyways say:

line = "$W5M5A,100527,142500,730301c44892fd1c,2,686.5  4,333.96,0,0,28.6,123,75,-0.4,1.4*49"

I want to strip out the spaces. I thought you would just do this

line = line.strip()

but now line is still '$W5M5A,100527,142500,730301c44892fd1c,2,686.5 4,333.96,0,0,28.6,123,75,-0.4,1.4*49' instead of '$W5M5A,100527,142500,730301c44892fd1c,2,686.54,333.96,0,0,28.6,123,75,-0.4,1.4*49'

any thoughts?

Upvotes: 3

Views: 1209

Answers (2)

momo
momo

Reputation: 1045

another way of doing it

line = ''.join(line.split())

Upvotes: 0

line = line.replace(' ', '')

Upvotes: 11

Related Questions