Re: string replace for back slash

2009-02-05 Thread S.Selvam Siva
On Thu, Feb 5, 2009 at 5:59 PM, wrote: > "S.Selvam Siva" wrote: > > I tried to do a string replace as follows, > > > > >>> s="hi & people" > > >>> s.replace("&","\&") > > 'hi \\& people' > > >>> > > > > but i was expecting 'hi \& people'.I dont know ,what is something > different > > here with e

Re: string replace for back slash

2009-02-05 Thread Chris Rebert
On Thu, Feb 5, 2009 at 3:40 AM, S.Selvam Siva wrote: > Hi all, > > I tried to do a string replace as follows, > s="hi & people" s.replace("&","\&") > 'hi \\& people' > > but i was expecting 'hi \& people'.I dont know ,what is something different > here with escape sequence. The Pyt

Re: string replace shortcut

2007-09-18 Thread Gabriel Genellina
En Tue, 18 Sep 2007 08:44:32 -0300, <[EMAIL PROTECTED]> escribi�: > Hello, > > I am trying to replace some string with list objects: > my_text1="function1 function2" from my_module_with_functions_1 import * from my_module_with_functions_2 import * > > # functions in module " my_mo

Re: String Replace only if whole word?

2006-11-19 Thread Leonhard Vogt
Michael Yanowitz schrieb: > Yeah, I am operating this on a Python script. However, I am working off > a requirement that the script be pre-processed and the strings replaced > before executing the script and that if there are any remaining (not > replaced) > names that I don't execute the script

Re: String Replace only if whole word?

2006-11-17 Thread Tim Chase
> I have been using the string.replace(from_string, to_string, len(string)) > to replace names in a file with their IP address. > For example, I have definitions file, that looks something like: > 10.1.3.4 LANDING_GEAR > 20.11.222.4 ALTIMETER_100 > 172.18.50.138 SIB > 172.18.50.138 LAPTOP >

RE: String Replace only if whole word?

2006-11-17 Thread Michael Yanowitz
>Michael Yanowitz wrote: >> Hello: >> >> I am hoping someone knows if there is an easier way to do this or someone >> already implemented something that does this, rather than reinventing the >> wheel: >> I have been using the string.replace(from_string, to_string, len(string)) >> to replace na

Re: String Replace only if whole word?

2006-11-17 Thread Juho Schultz
Michael Yanowitz wrote: > Hello: > > I am hoping someone knows if there is an easier way to do this or someone > already implemented something that does this, rather than reinventing the > wheel: > I have been using the string.replace(from_string, to_string, len(string)) > to replace names in a

Re: string replace

2006-07-01 Thread Michele Petrazzo
[EMAIL PROTECTED] wrote: > Check out the .translate method and the string.maketrans documentation. > You can use it to delete a list of characters all in one line: > Yes. This is, more or less, what I were looking for. P.s. Sure, if replace could accept a tuple... :) Thanks to all, Michele --

Re: string replace

2006-06-30 Thread johnzenger
Check out the .translate method and the string.maketrans documentation. You can use it to delete a list of characters all in one line: >>> s = "I am the walrus" >>> import string >>> s.translate(string.maketrans("",""),"aeiou") 'I m th wlrs' Michele Petrazzo wrote: > Hi, > a lot of times I nee

Re: string replace

2006-06-30 Thread Jim Segrave
In article <[EMAIL PROTECTED]>, Michele Petrazzo <[EMAIL PROTECTED]> wrote: >Hi, >a lot of times I need to replace more than one char into a string, so I >have to do something like > >value = "test" >chars = "e" >for c in chars: > value = value.replace(c, "") > >A solution could be that "replace

Re: string replace

2006-06-30 Thread Tim Chase
> a lot of times I need to replace more than one char into a > string, so I have to do something like > > value = "test" > chars = "e" > for c in chars: >value = value.replace(c, "") > > A solution could be that "replace" accept a tuple/list of > chars, like that was add into the new 2.5 for

Re: string replace

2006-06-30 Thread Schüle Daniel
> A solution could be that "replace" accept a tuple/list of chars, like > that was add into the new 2.5 for startswith. > > I don't know, but can be this feature included into a future python > release? I don't know, but I think it would be useful as for now I use this >>> import re >>> cha

RE: string replace

2006-06-30 Thread Cihal Josef
Hi Mechele, In string s u want to replace string "b" or "c" to -> "x" import re s ="a1b2c3" re.sub("[bc]","x",s) Sincerely josef Josef -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michele Petrazzo Sent: Friday, June 30, 2006 4:03 PM To: pytho

[OT] Re: String Replace Problem...

2005-02-28 Thread Steven Bethard
Sean McIlroy wrote: Alright, now it's too much. It's not enough that you're eliminating it from the language, you have to stigmatize the lambda as well. You misunderstand me. I don't have a problem with lambda when it's appropriate, e.g. when used as an expression, where a statement is forbidden

Re: String Replace Problem...

2005-02-28 Thread Sean McIlroy
Alright, now it's too much. It's not enough that you're eliminating it from the language, you have to stigmatize the lambda as well. You should take some time to reflect that not everybody thinks the same way. Those of us who are mathematically inclined like the lambda because it fits in well with

Re: String Replace Problem...

2005-02-28 Thread Steven Bethard
Sean McIlroy wrote: f = lambda x: (x[0]=='@' and x[6:] + '.0') or (x=='/' and x + '\n') or x See "Inappropriate use of Lambda" in http://www.python.org/moin/DubiousPython. You're creating a named function, so there's no reason to use the anonymous function syntax. Try: def f(x): return (x[

Re: String Replace Problem...

2005-02-28 Thread Sean McIlroy
I can't claim to have studied your problem in detail, but I get reasonable results from the following: filename = 'Errors.txt' S = open(filename,'r').read().split() f = lambda x: (x[0]=='@' and x[6:] + '.0') or (x=='/' and x + '\n') or x open(filename,'w').write(' '.join(map(f,S))) HTH -

Re: String Replace Problem...

2005-02-28 Thread wes weston
[EMAIL PROTECTED] wrote: Hello NG, probably this is a basic question, but I'm going crazy... I am unable to find an answer. Suppose that I have a file (that I called "Errors.txt") which contains these lines: MULTIPLY 'PERMX' @PERMX1 1 34 1 20 1 6 / 'PERMX' @PERMX2 1 34 21 41

Re: String Replace Problem...

2005-02-28 Thread Peter Hansen
[EMAIL PROTECTED] wrote: 'PERMX' @PERMX1 1 34 1 20 1 6 / ... 'PERMX' @PERMX10 1 34 21 41 29 34/ ... I would like to replace all the occurrencies of the "keywords" (beginning with the @ (AT) symbol) with some floating point value. As an example, this is what I do: # Find All Keyw