On 6/23/07, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote:
>
> On 23-Jun-07, at 10:39 AM, Sudev Barar wrote:
> > I am writing some intranet pages under ~/public_html directory. As I
> > keep adding more and more pages under this directory I want to create
> > a index.html page here that will constantly update itself whenever a
> > new page is added and provide a link to that page.
>
> something like this, assuming you list of links is in a file called
> filelist. Run as a cron job or manually everytime you add a file
>
> #!/usr/bin/python
>
> import os
>
> f = open('/var/www/html/filelist','a')
>
> for fle in os.listdir('/var/www/html/'):
> if os.path.splitext(fle)[1] == '.html':
> lne = """<a href = "./%s">%s</a>""" %(fle,fle)
> if lne not in f.readlines():
> f.write(lne)
> f.close()
I don't think this code will work. In 'a' (append mode) we cannot
write (append) and read at the same time.
Also, any specific reason you choose to append to an existing file?
What advantage it has over writing the file (from scratch) again?
Regards and best wishes,
--
Rahul Upakare
_______________________________________________
ilugd mailinglist -- [email protected]
http://frodo.hserus.net/mailman/listinfo/ilugd
Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi
http://www.mail-archive.com/[email protected]/