[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Orgmode] OT: Python help
From: |
Xiao-Yong Jin |
Subject: |
Re: [Orgmode] OT: Python help |
Date: |
Tue, 20 Jul 2010 14:03:49 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
On Tue, 20 Jul 2010 14:08:32 +0100, Peter Westlake wrote:
> On Tue, 20 Jul 2010 16:58 +0530, "Puneeth" <address@hidden> 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 */\ <
- [Orgmode] OT: Python help, Carsten Dominik, 2010/07/20
- Re: [Orgmode] OT: Python help, Giovanni Ridolfi, 2010/07/20
- Re: [Orgmode] OT: Python help, Carsten Dominik, 2010/07/20
- Re: [Orgmode] OT: Python help, Puneeth, 2010/07/20
- Re: [Orgmode] OT: Python help, Carsten Dominik, 2010/07/20
- Re: [Orgmode] OT: Python help, Puneeth, 2010/07/20
- Re: [Orgmode] OT: Python help, Peter Westlake, 2010/07/20
- Re: [Orgmode] OT: Python help, Carsten Dominik, 2010/07/20
- Re: [Orgmode] OT: Python help,
Xiao-Yong Jin <=
- Re: [Orgmode] OT: Python help, Giovanni Ridolfi, 2010/07/20