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?
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.
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".
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With