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 value. I
don't know what
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 FILE.
[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 is an extra
[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))
print line
But
hm...Is there a way to get rid of the newline in print?
--
http://mail.python.org/mailman/listinfo/python-list
Got it, thanks all!
--
http://mail.python.org/mailman/listinfo/python-list
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
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 in the
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 print, use
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?
--
[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 in advance
[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 in advance
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
don't know what
[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 in advance
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
[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
16 matches
Mail list logo