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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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