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

Jacob S. keridee at jayco.net
Sun Dec 5 23:20:31 CET 2004


Hi!

Can I ask a few questions? (Other than this one...)
What output did you expect? A string, tuple, or what? I'm not strong with
cgi stuff.
Also, you don't need the string module 1) because you don't use it 2)
because you can use string methods.

Jacob Schmidt

> 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
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>



More information about the Tutor mailing list