Sunday, March 10, 2013

Python - Value Error Unsupported Format Character

I had a simple python code working with URLs which caused an error of the form: "unsupported format character 'p' (0x70) at index 72".

The code looks like:
num = 1
abc = "http://<site>?value=[abc%20def],value2=%d"
URL = abc % (num)

This is caused because of using the % sign in the string. We need to escape the % sign with another % sign.
So the new string looks like:
abc = "http://<site>?value=[abc%%20def],value2=%d"

References:
1. http://yuji.wordpress.com/2009/01/09/python-valueerror-unsupported-format-character-percent-sign-python-format-string/

No comments:

Post a Comment