whitespace within a string
From: Bart Nessux (bart_nessux_at_hotmail.com)
Date: 02/24/04
- Next message: Sean Ross: "Re: Learning Python on jEdit"
- Previous message: Robert Brewer: "RE: Python scripts in IIS"
- Next in thread: Jeff Epler: "Re: whitespace within a string"
- Reply: Jeff Epler: "Re: whitespace within a string"
- Reply: Erik Max Francis: "Re: whitespace within a string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 23 Feb 2004 20:22:25 -0500
Is there a function/module that can be used to throw out extra whitespace
that appears within a string? The problem that I have is this: Before any
configuration is done to my files, they have lines with tabs in between the
words like this:
"disable = yes"
After configuring the files using the operating system's administration
tools, the OS rewrites the files to contain spaces instead of tabs. So now,
the file looks like this:
"disable = yes"
I would like my script to work in either situation. Right now, it only works
with spaces, not tabs. Below is the script:
def enable_ssh():
# works on 10.3 systems, not 10.2 systems
import os
os.chdir('/etc/xinetd.d')
find = 'disable = yes'
replace = 'disable = no'
x = file('ssh')
data = x.read()
x.close()
search = str.find(data, find)
if search >= 0:
data = data.replace(find, replace)
outputFile = file('ssh', 'w')
outputFile.write(data)
outputFile.close()
print
print "SSH was disabled... service restarted!!!"
print
else:
print
print "SSH was enabled... no action taken."
print
enable_ssh()
- Next message: Sean Ross: "Re: Learning Python on jEdit"
- Previous message: Robert Brewer: "RE: Python scripts in IIS"
- Next in thread: Jeff Epler: "Re: whitespace within a string"
- Reply: Jeff Epler: "Re: whitespace within a string"
- Reply: Erik Max Francis: "Re: whitespace within a string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|