Removing whitespace in python -
i using python read headers sac having trouble removing whitespace. want remove space before next station name e.g rpz, toz, urz. code:
for s in stations: tr=st[0] h=tr.stats stnm = h.station tt = h.sac.t1 print>>f,stnm, 'p', '1', tt, i want output this:
dsz p 1 53.59rpz p 1 72.80toz p 1 40.25urz p 1 32.26 then go onto new line after 32.26. why have comma after tt.
however outputs unwanted space before rpz, toz , urz:
dsz p 1 53.59 rpz p 1 72.80 toz p 1 40.25 urz p 1 32.26 any suggestions? have tried x.strip(),
attributeerror: 'list' object has no attribute 'strip'.
the print statement adding spaces; if want space dropped, don't print use f.write() instead:
f.write('{} p 1 {}'.format(stnm, tt)) this uses string formatting str.format() create same output format, no space written following tt value.
Comments
Post a Comment