[Tutor] ValueError

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Wed, 24 Jan 2001 22:43:19 -0800 (PST)

On Thu, 25 Jan 2001, Suzanne Little wrote:

> Quick background:
> It's a script that generates an html page. There's a variable (BODY) with
> a large  string of html (in ''') and %(var_name)s in various places. The
> function takes a dictionary and does some bit's and pieces before
> html_string.append(BODY % dictionary) is called. This is where the
> following error is occuring.
> <--->
> File formatter.py, line 271, in build_single
>   html_string.append(BODY % dictionary)
> ValueError: unsupported format character '"' (0x22)

Try searching through your body for the string '%"' --- from the error
message, it sounds like that string is somewhere within your BODY.  Let's
see if we can duplicate that error message:

>>> """This is a test.%" Hello world!""" % 42  
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: unsupported format character '"' (0x22)

Ok, so that's one of the stronger possibilities out there.

> So I'm a bit puzzled. This is the second function of this type I've
> written and the first was fine. Any ideas where I should be looking?
> The code's really too long and ugly to post so hopefully the above is
> enough for someone to give me some clues.

Take a closer look at BODY --- a good approach is to selectively cut parts
of the string out, and isolate what portion of BODY is causing problems.  
Don't worry: I think you'll find this one pretty quickly.  Good luck!