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

Liam Clarke cyresse at gmail.com
Mon Dec 6 01:40:29 CET 2004


Try an intermediate step 
videodb={'title':title,'year':year,'director':director}

x=videodb['title'] #Sometimes this helps
print type(x)        #Check x is a string
print x                 #see if it's got stuff

#save to database
try:
  f=open(filename,'w')
except TypeError:
  print "the error is occurring on opening the file, which would mean
that it's variable filename which is causing the problem."
try:
    f.write(x)
except TypeError:
   print "The error is occurring on writing to the file, which means
the written values need to be checked."
f.close()

Good luck,

Liam Clarke






On Sun, 5 Dec 2004 17:46:39 -0500, Jacob S. <keridee at jayco.net> wrote:
> Your error message says that you are getting an empty string from your cgi
> variable. I IMHO would suggest printing videodb['title'] before writing it
> to a file to see what the variable contains. Or you might print out videodb
> to see what the dictionary looks like. My off the wall guess is that 1) Your
> cgi variables are not returning the value from the actual object that you
> want 2) The script is running and assigning values to title, etc. before the
> afore mentioned object is given a value. IOW, maybe you haven't assigned
> values to the form before you try to read them.
> Another suggestion. Comment out the file writing part and print everything
> to the screen to verify that the output is what you want. "When in doubt,
> print it out." - Jacob Schmidt
> 
> HTH,
> Jacob
> 
> 
> 
> > Quoting "Jacob S." <keridee at jayco.net>:
> >
> > > Hi!
> > >
> > > Can I ask a few questions? (Other than this one...)
> > > What output did you expect? A string, tuple, or what?
> >
> > A string output. When I create a dictionary variable from
> > the python shell like this:
> > videodb={'title':'Crash','year':'1996','director':'David Cronenberg'}
> >
> > and type in videodb['title'] afterwards python spits out the
> > value 'Crash'. That's fine I get a string as expected.
> > But when I try to write the value of videodb['title'] to
> > a file nothing gets written.
> > I hope I clarified the issue somewhat.
> >
> > > 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
> >
> > ok. I'll remove it. thanx.
> >
> > [snip]
> >
> > --
> > 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
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.


More information about the Tutor mailing list