On Jul 20, 2010, at 3:08 PM, Peter Westlake wrote:
On Tue, 20 Jul 2010 16:58 +0530, "Puneeth" <puncha...@gmail.com>
wrote:
On Tue, Jul 20, 2010 at 4:50 PM, Puneeth <puncha...@gmail.com> wrote:
On Tue, Jul 20, 2010 at 4:43 PM, Carsten Dominik <domi...@uva.nl>
wrote:
Please show me the full line of code, I am currently editing a
python script
without any knowledge of python...
my_string = "Hello\nWorld"
my_new_string = my_string.replace("\n", "\n> ")
Sorry, this code (obviously) doesn't prepend ">" to the first line
Add this line to do that.
my_new_string = "> " + my_new_string
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
Peter.
Great. I learned something today. Thanks!
- Carsten
- Carsten
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode