with open("data.txt") as fin:
for line in fin:
line = line.rstrip('\n')
while line.endswith('\\'):
line = line[:-1] + next(fin).rstrip('\n')
print line
...
You can also pull this out into a generator if you wish
def continuation_lines(fin):
for line in fin:
line = line.rstrip('\n')
while line.endswith('\\'):
line = line[:-1] + next(fin).rstrip('\n')
yield line
with open("long.txt") as fin:
for line in continuation_lines(fin):
...