Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75301 > unrolled thread

reading text files with indentation

Started byNoah <noah-list@enabled.com>
First post2014-07-27 23:25 -0700
Last post2014-07-27 23:25 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  reading text files with indentation Noah <noah-list@enabled.com> - 2014-07-27 23:25 -0700

#75301 — reading text files with indentation

FromNoah <noah-list@enabled.com>
Date2014-07-27 23:25 -0700
Subjectreading 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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web