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


Groups > comp.lang.python > #75301

reading text files with indentation

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <noah-list@enabled.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:text': 0.05; 'that?': 0.05; 'lines:': 0.09; 'lost.': 0.09; 'subject:files': 0.09; 'cheers': 0.12; '"r")': 0.16; 'files:': 0.16; 'line)': 0.16; 'print': 0.22; 'header:User-Agent:1': 0.23; 'file.': 0.24; 'correct': 0.29; 'code': 0.31; 'getting': 0.31; 'lines': 0.31; '"",': 0.31; 'file:': 0.31; 'indentation': 0.31; 'file': 0.32; 'text': 0.33; 'open': 0.33; 'there,': 0.34; 'subject:with': 0.35; 'received:76': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'read': 0.60
X-Virus-Scanned Debian amavisd-new at enabled.com
Date Sun, 27 Jul 2014 23:25:20 -0700
From Noah <noah-list@enabled.com>
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
MIME-Version 1.0
To python-list@python.org
Subject reading text files with indentation
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Mailman-Approved-At Mon, 28 Jul 2014 09:28:35 +0200
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12379.1406532516.18130.python-list@python.org> (permalink)
Lines 17
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1406532516 news.xs4all.nl 2857 [2001:888:2000:d::a6]:60096
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:75301

Show key headers only | View raw


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


Thread

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

csiph-web