Re: Newbie question: string replace

2005-11-16 Thread Don
Diez B. Roggisch wrote: > [EMAIL PROTECTED] wrote: > > I have a config file with the following contents: > > service A = { > > params { > > dir = "c:\test", > > username = "test", > > password = "test" > > } > > } > > > > I want to find username and replace the value with another v

Re: Newbie question: string replace

2005-10-28 Thread Alex Martelli
Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Fri, 28 Oct 2005 12:27:36 -0700, [EMAIL PROTECTED] wrote: > > > hm...Is there a way to get rid of the newline in "print"? > > Yes, by using another language *wink* Ending the print statement with a comma also works;-) > Or, instead of using pri

Re: Newbie question: string replace

2005-10-28 Thread Alex Martelli
Mike Meyer <[EMAIL PROTECTED]> wrote: > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > > > So how to overwrite the config file directly in script.py instead of > > running script.py with two params? > > Don't overwrite the file directly. Save a copy, then rename it. That See module fileinput

Re: Newbie question: string replace

2005-10-28 Thread Steven D'Aprano
On Fri, 28 Oct 2005 12:27:36 -0700, [EMAIL PROTECTED] wrote: > hm...Is there a way to get rid of the newline in "print"? Yes, by using another language *wink* Or, instead of using print, use sys.stdout.write(). -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie question: string replace

2005-10-28 Thread [EMAIL PROTECTED]
Got it, thanks all! -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie question: string replace

2005-10-28 Thread [EMAIL PROTECTED]
hm...Is there a way to get rid of the newline in "print"? -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie question: string replace

2005-10-28 Thread Mike Meyer
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > Now it works: > rex = re.compile(r'(^.*username *=[^"]*")([^"]*)(".*$)') > for line in fileinput.input(FILE, inplace=1): > m = rex.match(line) > if m is not None: > line = "%s%s%s\n" % (m.group(1), new_name, m.group(3)) > pr

Re: Newbie question: string replace

2005-10-28 Thread Steve Holden
[EMAIL PROTECTED] wrote: > Now it works: > rex = re.compile(r'(^.*username *=[^"]*")([^"]*)(".*$)') > for line in fileinput.input(FILE, inplace=1): > m = rex.match(line) > if m is not None: > line = "%s%s%s\n" % (m.group(1), new_name, m.group(3)) > print line > > But there

Re: Newbie question: string replace

2005-10-28 Thread [EMAIL PROTECTED]
Now it works: rex = re.compile(r'(^.*username *=[^"]*")([^"]*)(".*$)') for line in fileinput.input(FILE, inplace=1): m = rex.match(line) if m is not None: line = "%s%s%s\n" % (m.group(1), new_name, m.group(3)) print line But there is an extra line break after each line in F

Re: Newbie question: string replace

2005-10-25 Thread Mike Meyer
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > So how to overwrite the config file directly in script.py instead of > running script.py with two params? Don't overwrite the file directly. Save a copy, then rename it. That way, you don't replace the new version until you know the old version is

Re: Newbie question: string replace

2005-10-25 Thread [EMAIL PROTECTED]
So how to overwrite the config file directly in script.py instead of running script.py with two params? A XML file or ConfigParser is appealing but this is part of a legacy system...:( -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie question: string replace

2005-10-25 Thread davideugenewarren
[EMAIL PROTECTED] wrote: > I have a config file with the following contents: > service A = { > params { > dir = "c:\test", > username = "test", > password = "test" > } > } > > I want to find username and replace the value with another value. I > don't know what the username value i

Re: Newbie question: string replace

2005-10-25 Thread Steven D'Aprano
On Tue, 25 Oct 2005 09:37:09 -0700, [EMAIL PROTECTED] wrote: > I have a config file with the following contents: > service A = { > params { > dir = "c:\test", > username = "test", > password = "test" > } > } > > I want to find username and replace the value with another value. I >

Re: Newbie question: string replace

2005-10-25 Thread Larry Bates
[EMAIL PROTECTED] wrote: > I have a config file with the following contents: > service A = { > params { > dir = "c:\test", > username = "test", > password = "test" > } > } > > I want to find username and replace the value with another value. I > don't know what the username value i

Re: Newbie question: string replace

2005-10-25 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote: > I have a config file with the following contents: > service A = { > params { > dir = "c:\test", > username = "test", > password = "test" > } > } > > I want to find username and replace the value with another value. I > don't know what the username value i

Newbie question: string replace

2005-10-25 Thread [EMAIL PROTECTED]
I have a config file with the following contents: service A = { params { dir = "c:\test", username = "test", password = "test" } } I want to find username and replace the value with another value. I don't know what the username value in advance though. How to do it in python? --