From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xiao-Yong Jin Subject: Re: OT: Python help Date: Tue, 20 Jul 2010 14:03:49 -0400 Message-ID: <8739ve9gje.fsf@columbia.edu> References: <97ED60B0-D01C-47DB-9B5E-10F1B39E3892@uva.nl> <83vd8a1kkv.fsf@yahoo.it> <606EFD47-1329-43F8-8496-1A0B0A2390E9@uva.nl> <1279631312.15948.1385772637@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=46047 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ObHAe-0007Rj-UF for emacs-orgmode@gnu.org; Tue, 20 Jul 2010 14:04:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1ObHAd-0002aO-Qn for emacs-orgmode@gnu.org; Tue, 20 Jul 2010 14:04:00 -0400 Received: from serrano.cc.columbia.edu ([128.59.29.6]:33697) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1ObHAd-0002ZB-ON for emacs-orgmode@gnu.org; Tue, 20 Jul 2010 14:03:59 -0400 In-Reply-To: <1279631312.15948.1385772637@webmail.messagingengine.com> (Peter Westlake's message of "Tue, 20 Jul 2010 14:08:32 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Peter Westlake Cc: Carsten Dominik , emacs-org list On Tue, 20 Jul 2010 14:08:32 +0100, Peter Westlake wrote: > On Tue, 20 Jul 2010 16:58 +0530, "Puneeth" wrote: > Here's a Pythonic way to do it, tested: > import re > my_string = "Hello\nWorld" > pattern = re.compile('^',re.MULTILINE) > my_new_string = re.sub(pattern, '> ', my_string) > This still might not be quite right, as it will turn "Hello\nWorld\n" > into "> Hello\n> World\n> ". Avoid that by using a negative lookahead > for the end of the string: > my_string = "Hello\n\nWorld\n" > pattern = re.compile('^(?!\Z)',re.MULTILINE) > my_new_string = re.sub(pattern, '> ', my_string) > print my_new_string > gives: >> Hello >> >> World Although python does not recommend TIMTOWTDI, but I would use the following function s = lambda str: ''.join(['< ' + s for s in str.splitlines(True)]) s("Hello\n\nWorld\n") I think it is much nicer and clearer to me -- probably because I use a lot of haskell. And the following is the function s in haskell s = unlines . map ("< " ++) . lines Just my 2c. -- J c/* __o/* X <\ * (__ Y */\ <