reading text files with indentation

Noah noah-list at enabled.com
Mon Jul 28 08:25:20 CEST 2014


Hi there,

The following code I am using to read in lines from a text file.  The 
indentation of the text is getting lost.  How can I correct that?


     for file in files:
       	with open (file, "r") as file:
	    lines = file.readlines()

	for line in lines:
             line = re.sub("#.*", "", line)
             line = line.strip()
             policy_lines.append(line)
             print line

Cheers



More information about the Python-list mailing list