With the strip() function the \n does not strip and instead changes the string (I don't know how to describe it, test for yourself)
lines = []
line = str(pw.readlines())
print(line)
x = line.strip("\n")
x = line.strip("\t")
lines.append(x)
print(lines)enter code here
edit:
here is the output I get from debugging:
here is the original string: ['pqrm \n', 'google \n', '8'] After I try to strip it I get: ["['pqrm \n', 'google \n', '8']"] Sorry not the best with python or stackoverflow
CodePudding user response:
One can use re.sub, to get rid of newlines, tabs, spaces.
import re
st = "['pqrm \n', 'google \n', '8']"
print(re.sub(r'[\n\t\s] ','', st))
['pqrm','google','8']
CodePudding user response:
You are sending the list of values as a string, instead of each value one by one. So try this...
lines = []
for line in pw.readlines():
x = line.strip("\n").strip("\t")
lines.append(x)
print(lines)