writing output to file
Ralf Claus
102030405 at gmx.net
Thu Jul 11 15:17:20 EDT 2002
"Allan Wermuth" <alw at gate2.dda.dk> schrieb im Newsbeitrag
news:agklgl$rvu$1 at news.net.uni-c.dk...
> Inspired by an existing Perl script, I wrote this chunk of code, but
instead
> of
> writing the result to the screen, I would like to write output to a
another
> file.
>
> #!/usr/bin/python
dat=open('test.txt','w')
> for line in open('/etc/passwd').readlines() :
> if line.strip()[0] == '#': continue
>
> temp = line.split(':')
> if int(temp[2]) > 100 :
> print "%10s %30s" % (temp[0], temp[4])
out="%10s %30s" % (temp[0], temp[4])
dat.write(out)
dat.close()
>
> How can I do that?
> It's possibly quite simple, in Perl it is ;-) , but I am trying to learn
> Python, so
> I would appreciate if someone would help me out.
>
> /Allan Wermuth
>
>
>
More information about the Python-list
mailing list