<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 07/27/2014 11:25 PM, Noah wrote:<br>
</div>
<blockquote cite="mid:53D5ECD0.8010702@enabled.com" type="cite">Hi
there,
<br>
<br>
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?
<br>
<br>
<br>
for file in files:
<br>
with open (file, "r") as file:
<br>
lines = file.readlines()
<br>
<br>
for line in lines:
<br>
line = re.sub("#.*", "", line)
<br>
line = line.strip()
<br>
</blockquote>
<br>
The <b>strip</b> method on strings removes all whitespace from both
ends. There goes your indentation.<br>
<br>
<blockquote cite="mid:53D5ECD0.8010702@enabled.com" type="cite">
policy_lines.append(line)
<br>
print line
<br>
<br>
Cheers
<br>
</blockquote>
<br>
Example:<br>
<br>
>>> " abc ".strip()<br>
'abc'<br>
<br>
<br>
Gary Herron<br>
<br>
</body>
</html>