I want to remove \n from the beginning lines like this \n id int(10) NOT NULL. I tried strip(), rstrip(), lstrip() replace('\n', ''). I don’t get it. What am I doing wrong?
print(column)
print(column.__class__)
x = column.rstrip('\n')
print(x)
x = column.lstrip('\n')
print(x)
x = column.strip('\n')
print(x)
print(repr(column))
gives
\n id int(10) NOT NULL
<type 'str'>
\n id int(10) NOT NULL
\n id int(10) NOT NULL
\n id int(10) NOT NULL
\n id int(10) NOT NULL
'\\n `id` int(10) NOT NULL'
Are you sure that
\nis a newline instead of a literal\followed by a literaln? In that case, you’d want:Probably a better way is to check if it starts with
\nbefore stripping, and then use slicing:or even more robustly,
re.sub:Based on the symptoms you describe above, I’m almost positive this is the case.