Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75301 > unrolled thread
| Started by | Noah <noah-list@enabled.com> |
|---|---|
| First post | 2014-07-27 23:25 -0700 |
| Last post | 2014-07-27 23:25 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
reading text files with indentation Noah <noah-list@enabled.com> - 2014-07-27 23:25 -0700
| From | Noah <noah-list@enabled.com> |
|---|---|
| Date | 2014-07-27 23:25 -0700 |
| Subject | reading text files with indentation |
| Message-ID | <mailman.12379.1406532516.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web