> running the following with print i uncommented does print each line
to
> stdout. but it doesn't write to the appropriate file...
Does it do anything?
BTW YOu don;t need to touch a file, the 'w' parameter will
create a new file if one doesn't exist.
> c) I originally wanted to delete lines over 2085 in length but
couldn't
> find a way to do that... did I miss it?
deleting files from a file aint so easy, its much simpler to just
create a new file with the lines you want, as you do here.
> srcfile = open('/var/log/httpd-access.log.bak', 'r')
> dstfile = open('/var/log/httpd-access.log', 'w')
> while 1:
> lines = srcfile.readlines()
> if not lines: break
> for i in lines:
This is much easier with:
for i in srcfile:
It will automatically detect and stop at the end of the file.
> if len(i) < 2086:
> #print i
> dstfile.write(i)
You should add a newline character otherwise you will just
get one enormously long line!
dstfile.write(i+'\n')
> srcfile.close()
> dstfile.close()
But I don't see anything obviously wrong.
What exactly does happen? A single line as explained above?
Or just a blank file?
Alan G.
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor