Reputation: 1
For a line in a given source(f
),
0x223f01 X 32 fhsjskk, \
below code still picks this line and print it.
for line in f:
line.rstrip('\n') # every line has \n
if not line.endswith('\\'):
print(line)
In this scenario, one cannot avoid trailing backslash from the source.
How to detect trailing backslash characters?
Upvotes: 0
Views: 42
Reputation: 629
rstrip()
returns the stripped string, it does not change the string itself. try:
line = line.rstrip('\n')
See: string.rstrip()
Documentation
Upvotes: 3
Reputation: 1972
The rstrip
function does not modify the original string, you need to change that line to line = line.rstrip('\n')
Upvotes: 1