CGI Webcounter not quite working...help, please

J. W. McCall no at spam.com
Tue Aug 5 18:44:57 CEST 2003


Sorry again if this is OT; I'm not sure if this is a python problem or 
just a CGI problem, but I couldn't find a decent CGI NG.  Let me know if 
there's somewhere else I should be posting.

I got this webcounter to be called directly (I still can't get it to be 
called from an HTML file with #exec or #include or anything).

Now the problem is that the part of the script that updates the count 
file doesn't work.  It's like it doesn't even execute.

Here's the script; don't worry, it's short and simple (I'm a Python 
beginner)

#!/usr/pkg/bin/python

print "Content-Type: text/html\n\n"
print "\n\n"

import os
import string

print "<HTML>"
print "<BODY>"
filenames = os.listdir(os.curdir)

if "count.txt" in filenames:
    input = open('count.txt', 'r')
    i = string.atoi(input.read(1))
else:
    i = 0
    print "File doesnt exist<BR>"

i = i + 1
print "This page has been accessed " + `i` + " times.<BR>"
print "</BODY>"
print "</HTML>"

#it doesn't seem to execute this at all
output = open('count.txt', 'w')
output.write(`i`)
output.close()

Do you see any obvious problems with this?  It works fine when I call it 
from the command line.

It's on my Freeshell shell account.  It's a NetBSD system, I believe.

Any advice, ideas?

Thanks,

J. W. McCall





More information about the Python-list mailing list