[Tutor] CGI Video collection application File I/O troubles

Guybrush Threepwood domain.admin at online.ie
Sun Dec 5 23:08:10 CET 2004


Hello!

I am having some problems with a simple CGi application I am
coding for my gf. It is supposed to be a video collection
program. I can't manage to write the value of a dictionary
key to a file. Like thisL
f.write(videodb['title'])

It just creates a blank file. When i try to access the
videodb['title'] key from the python shell it prints
out the correct value respecitvely. Even when I use the
print command to write to a HTML file it outputs the
correct value of videodb['title'] for example.
When I run the script in python shell it says:
TypeError: argument 1 must be string or read-only character buffer, not None

Why doesn't it write the value to the file?

Here's the complete source code:

#!/usr/bin/python
import cgi,string

filename='/var/www/cgi-bin/videodb'
print "Content-type: text/html\n"

#extract variable s
form=cgi.FieldStorage()
title=form.getvalue("title")
year=form.getvalue("year")
director=form.getvalue("director")

videodb={'title':title,'year':year,'director':director}

#save to database
f=open(filename,'w')
f.write(videodb['title'])
f.close()

--
The lady on the call box in Monkey Island 2
Guybrush: I'm lost in the Inky Island Jungle in Monkey 2
Lady: Just walk off the edge of the screen


More information about the Tutor mailing list