Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75301
| Date | 2014-07-27 23:25 -0700 |
|---|---|
| From | Noah <noah-list@enabled.com> |
| Subject | reading text files with indentation |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12379.1406532516.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
reading text files with indentation Noah <noah-list@enabled.com> - 2014-07-27 23:25 -0700
csiph-web