Having problems with strings in HTML

John Machin sjmachin at lexicon.net
Mon Jun 26 19:29:16 EDT 2006


On 27/06/2006 7:51 AM, Kiana Toufighi wrote:
> Hi,
> 
> I get a very odd error:
> ValueError: unsupported format character 't' (0x74) at index 237
> 
> Here's my code:
> HI_LITE_FILE_NAME = '/var/tmp/out.txt'
> 
> print '''
>            <a 
> href="http://bbc.botany.utoronto.ca/ntools/cgi-bin/ntools_treeview_word.cgi?input=&max=2&values_off=no&remove_bracket=no&show_line_nr=yes&show_link_out=yes&decimal_places=10&show_classification=yes&db=arabidopsis&selection=any%20term&mode=&mode_nos=&yellow_blue=yes&local_file_name=%(OUT_FILE_NAME)s&show_instructions=no&expt_link=NASCArrays&max_adjust=2&view_size=large&highlight=%(HI_LITE_FILE_NAME)s">GraphicalOutput</a> 
> 
>         ''' % {'OUT_FILE_NAME': OUT_FILE_NAME, 'HI_LITE_FILE_NAME': 
> HI_LITE_FILE_NAME}

That code produces:
NameError: name 'OUT_FILE_NAME' is not defined
When that is remedied, *then* one gets the ValueError.
*Please*, when asking a question, post exactly the code that you ran, 
and include the full traceback, not just the last line.

> 
> I wonder if this has something to do with HTML's % character.

I'm not sure why you are wondering. The error message told you exactly 
what the problem was and exactly where it was (offset 237) in your 
format string. . Your format string (the first operand of the string % 
operator) contains ...&selection=any%20term... and the %20t looks like a 
formatting operation, but (like it said) 't' is not valid.

To overcome this you would need to escape any '%' that is actually part 
of the URL by doubling it ...&selection=any%%20term...

This is nothing to do with HTML ... *any* stray '%' will give you grief:

|>> '1% of %s are difficult to understand' % 'error messages'
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: int argument required


Have you read this:
http://docs.python.org/lib/typesseq-strings.html
?
It may help.

Cheers,
John



More information about the Python-list mailing list