Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.043 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'python': 0.08; 'advice?': 0.09; 'method:': 0.09; 'am,': 0.12; 'useful,': 0.15; 'cleans': 0.16; 'whitespace.': 0.16; 'cc:addr:python-list': 0.16; 'looked': 0.16; 'wrote:': 0.18; 'thanks,': 0.18; 'that?': 0.18; 'possibly': 0.19; 'cc:no real name:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.24; 'code': 0.25; 'script.': 0.29; 'cc:addr:python.org': 0.29; 'strings,': 0.30; 'whitespace': 0.30; 'break': 0.32; "can't": 0.32; 'message-id:@gmail.com': 0.33; 'header:User-Agent:1': 0.33; 'anything': 0.34; 'function.': 0.34; 'something': 0.35; 'url:python': 0.36; 'file': 0.36; 'beginning': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'think': 0.37; 'using': 0.38; 'received:10.0.0': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'useful': 0.38; 'easier': 0.38; 'non': 0.38; 'clearly': 0.39; 'url:docs': 0.39; 'url:org': 0.39; "it's": 0.40; 'received:209': 0.40; 'simple,': 0.64; 'url:3': 0.67; '11:49': 0.84; 'andrea': 0.84; 'hook': 0.84; 'url:lib': 0.84; 'reliable,': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=vo6xkDgOI3p/hcXU/xgryRLyEZ79YmidipXNYQ0RFwI=; b=HxG4u7LsVNJlj6FMKY/xjV/J6whNop9+9qKDEjiiMvLEe9zy0DZPLxzUVbub5Yq1+L LUQZqU5soyzFxq98wrbnNW1KaocQD0yPKN8B+1S6ZBrmk8LhHEZIXkO1Rd0q13Hq6fD3 /hIkBau/TvOmtMV/rKWwQ7d1FEezyV5w2k24w= Date: Tue, 06 Dec 2011 11:59:57 +0000 From: Andrea Crotti User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111108 Thunderbird/8.0 MIME-Version: 1.0 To: "Pedro Henrique G. Souto" Subject: Re: whitespace cleanup References: <4EDDFC48.2000903@gmail.com> <4EDE0166.1030006@gmail.com> In-Reply-To: <4EDE0166.1030006@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323172811 news.xs4all.nl 6939 [2001:888:2000:d::a6]:53788 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16720 On 12/06/2011 11:49 AM, Pedro Henrique G. Souto wrote: > On 06/12/2011 09:28, Andrea Crotti wrote: > > Now on Emacs I have a hook before every save that cleans up all the > > "wrong" white spaces, > > with the 'whitespace-cleanup' function. > > > > I would like that also for my non emacsers colleagues, and possibly > with > > a Python script. > > I looked up around but I can't find anything useful, any advice? > > You can use the strip() method: > [http://docs.python.org/release/2.3/lib/module-string.html] > > While reading the file as strings, the strip() method rips out all of > the extra whitespace. > > > Thanks, > > Andrea > > > > Good luck! > Well it's not so simple, I clearly don't want to strip out whitespace in the beginning of the line, or my nice code will break miserably ;) So I think some magic using tokens/regexp/python grammar would be useful to do something reliable, or is it easier than that?