python - Whitespace removing in file -
i want remove whitespaces in file using python. that, using:
output = "file.out" open(output) templist: templ = templist.read().splitlines() filelist = [] line in templ: if line.startswith("something"): filelist.append(line.strip(' '))
i managed append required lines, whitespace removing not work. can me? =]
.strip()
removes whitespace start , end of string.
i think easiest way go use regex:
import re ... line in templ: if line.startswith("something"): filelist.append(re.sub(r"\s+", "", line))
\s
matches kind of whitespace (spaces, newlines, tabs etc.).
Comments
Post a Comment