From: Xiao-Yong Jin <xj2106@columbia.edu>
To: Peter Westlake <peter.westlake@pobox.com>
Cc: Carsten Dominik <dominik@uva.nl>, emacs-org list <emacs-orgmode@gnu.org>
Subject: Re: OT: Python help
Date: Tue, 20 Jul 2010 14:03:49 -0400 [thread overview]
Message-ID: <8739ve9gje.fsf@columbia.edu> (raw)
In-Reply-To: <1279631312.15948.1385772637@webmail.messagingengine.com> (Peter Westlake's message of "Tue, 20 Jul 2010 14:08:32 +0100")
On Tue, 20 Jul 2010 14:08:32 +0100, Peter Westlake wrote:
> On Tue, 20 Jul 2010 16:58 +0530, "Puneeth" <punchagan@gmail.com> 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 */\ <
next prev parent reply other threads:[~2010-07-20 18:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-20 10:47 OT: Python help Carsten Dominik
2010-07-20 11:03 ` Giovanni Ridolfi
2010-07-20 11:13 ` Carsten Dominik
2010-07-20 11:20 ` Puneeth
2010-07-20 11:25 ` Carsten Dominik
2010-07-20 11:28 ` Puneeth
2010-07-20 13:08 ` Peter Westlake
2010-07-20 13:12 ` Carsten Dominik
2010-07-20 18:03 ` Xiao-Yong Jin [this message]
2010-07-20 11:25 ` Giovanni Ridolfi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8739ve9gje.fsf@columbia.edu \
--to=xj2106@columbia.edu \
--cc=dominik@uva.nl \
--cc=emacs-orgmode@gnu.org \
--cc=peter.westlake@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).