Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Percentage sign not working

Tags:

python

html

I am working with a HTML application with Python. I usually use the % sign to indicate that I'm using a Python element, and never had a problem with that before.

Now, I am using some tables which I'm trying to control their size bye the percentage using the % sign. So now the Python does not show the Python elements.

Here is some code to explain myself:

<table width="90%">
<tr>
<td width="60%">HELLO</td>
<td width="40%">GOOD BYE</td>
</tr>
</table>

<input type="button" value="BUTTON" onclick="function(%s)" /> ''' % variable

The error that I am having says

unsupported format character '"' (0x22) at index 19"

making reference to the %s string in the onclick=function(%s)

Does someone know if the % sign in the tables affects Python or something like that?

like image 433
mauguerra Avatar asked Jan 23 '12 18:01

mauguerra


People also ask

How do I get the percentage sign on my keyboard?

On a US Keyboard layout, the percent sign is located on the numeral 5 key above the R and T. To insert % hold down the Shift key and press the 5 key. If you have a different Keyboard layout, it may be in some other place, but you can also insert it by holding down the Alt key and typing 037 on the numeric keypad.

How do you text a percent sign?

Usage in text It is often recommended that the percent sign only be used in tables and other places with space restrictions. In running text, it should be spelled out as percent or per cent (often in newspapers). For example, not "Sales increased by 24% over 2006" but "Sales increased by 24 percent over 2006".

Why does the percentage sign look like that?

The sign for "percent" evolved by gradual contraction of the Italian term per cento, meaning "for a hundred". The "per" was often abbreviated as "p."—eventually disappeared entirely. The "cento" was contracted to two circles separated by a horizontal line, from which the modern "%" symbol is derived.

How do I get the percentage sign on my iPhone?

See the iPhone battery percentage in the status bar On an iPhone with Face ID: Swipe down from the top-right corner. On an iPhone with a Home button: Go to Settings > Battery, then turn on Battery Percentage.


1 Answers

You need to escape '%' as '%%' in python strings. The error message you're getting probably is about the other percent signs. If you put only single percent sign in a string python thinks it will be followed by a format character and will try to do a variable substitution there.

In your case you should have:

'''

....
<table width="90%%">
<tr>
<td width="60%%">HELLO</td>
<td width="40%%">GOOD BYE</td>
</tr>
</table>

<input type="button" value="BUTTON" onclick="function(%s)" /> ''' % variable
like image 122
soulcheck Avatar answered Oct 01 '22 06:10

soulcheck