[Tutor] Brain Dead
Daniel Yoo
dyoo@hkn.EECS.Berkeley.EDU
Fri, 11 Aug 2000 12:47:43 -0700 (PDT)
On Fri, 11 Aug 2000 sysadmin@hiretechs.com wrote:
> Daniel,
>
> I appreciate your help. This is the code I wrote.
>
> #!/usr/bin/python
> import string
>
> myfile = open('master.hosts', 'r')
> for line in myfile.readlines():
> line = string.replace(line, '#', ';')
> if '\t' in line:
> line = string.replace(line, string.whitespace, 't\n\r\v\f')
> fields = string.split(line)
> if ';' in fields[0]:
> newline = ';' + fields[1] + '\t\tA\tIN\t' +
> fields[0][1:]
> else:
> newline = fields[1] + '\t\tA\tIN\t' + fields[0]
> print newline
Right now, all the results get printed out by that 'print' statement.
I'm guessing that instead of just printing out newline, you want to write
newline into your myfile. You can do this by replacing the print call
with a write call.
myfile.write(newline)
should do the trick.