Re: sed to python: replace Q

2008-06-04 Thread Dan Stromberg
On Tue, 06 May 2008 14:55:07 +, Raymond wrote: >>Another approach is to use the split() function in "re" module. > > Ah ha, thar's the disconnect. Thanks for all the pointers, my def is > now working. Still don't understand the logic behind this design > though. I mean why would any program

Re: sed to python: replace Q

2008-05-06 Thread Diez B. Roggisch
> Ah ha, thar's the disconnect. Thanks for all the pointers, my def is > now working. Still don't understand the logic behind this design though. > I mean why would any programming language have separate search or find > functions, one for regex and and another for non-regex based pattern > match

Re: sed to python: replace Q

2008-05-06 Thread Mel
Raymond wrote: > My other gripe is with the kludgy object-oriented regex functions. > Couldn't these be better implemented in-line? Why should I, as a coder, > have to 're.compile()' when all the reference languages do this at compile > time, from a much more straightforward and easy to read in-l

Re: sed to python: replace Q

2008-05-06 Thread Marco Mariani
Raymond wrote: Aren't sed, awk, grep, and perl the reference implementations of search and replace? I don't know about "reference implementations", but I daresay they are a mess w.r.t. usability. -- http://mail.python.org/mailman/listinfo/python-list

Re: sed to python: replace Q

2008-05-06 Thread Raymond
>Another approach is to use the split() function in "re" module. Ah ha, thar's the disconnect. Thanks for all the pointers, my def is now working. Still don't understand the logic behind this design though. I mean why would any programming language have separate search or find functions, one for

Re: sed to python: replace Q

2008-04-30 Thread Kam-Hung Soh
On Wed, 30 Apr 2008 17:12:15 +1000, Kam-Hung Soh <[EMAIL PROTECTED]> wrote: On Wed, 30 Apr 2008 15:27:36 +1000, Raymond <[EMAIL PROTECTED]> wrote: For some reason I'm unable to grok Python's string.replace() function. Just trying to parse a simple IP address, wrapped in square brackets, fr

Re: sed to python: replace Q

2008-04-30 Thread Kam-Hung Soh
On Wed, 30 Apr 2008 15:27:36 +1000, Raymond <[EMAIL PROTECTED]> wrote: For some reason I'm unable to grok Python's string.replace() function. Just trying to parse a simple IP address, wrapped in square brackets, from Postfix logs. In sed this is straightforward given: line = "date process text

Re: sed to python: replace Q

2008-04-30 Thread Robert Bossy
Raymond wrote: For some reason I'm unable to grok Python's string.replace() function. Just trying to parse a simple IP address, wrapped in square brackets, from Postfix logs. In sed this is straightforward given: line = "date process text [ip] more text" sed -e 's/^.*\[//' -e 's/].*$//' a

Re: sed to python: replace Q

2008-04-30 Thread happyriding
On Apr 29, 11:27 pm, Raymond <[EMAIL PROTECTED]> wrote: > For some reason I'm unable to grok Python's string.replace() function. line = "abc" line = line.replace("a", "x") print line --output:-- xbc line = "abc" line = line.replace("[apq]", "x") print line --output:-- abc Does the 5 character

Re: sed to python: replace Q

2008-04-29 Thread Lutz Horn
Hi, 2008/4/30 Raymond <[EMAIL PROTECTED]>: > For some reason I'm unable to grok Python's string.replace() function. replace() does not work with regular expressions. > Is there a decent description of string.replace() somewhere? Use re.sub(). >>> import re >>> line = "date process text [ip] m

sed to python: replace Q

2008-04-29 Thread Raymond
For some reason I'm unable to grok Python's string.replace() function. Just trying to parse a simple IP address, wrapped in square brackets, from Postfix logs. In sed this is straightforward given: line = "date process text [ip] more text" sed -e 's/^.*\[//' -e 's/].*$//' yet the following Pyt