[英]PYTHON - convert special character to string
我需要幫助。 有什么選項如何禁用隱式轉換特殊字符? 我的意思是:
#this is normal way with implicit convert special character
value = '\x55'
print value
>>> U
#and I would like to work with this value like with a string
print value
>>> \x55
您可能要使用原始字符串:
value = r'\x55'
使用{:x}
格式設置ord
字符的格式。
>>> print '\\x{:x}'.format(ord(value))
\x55
是的,但是有問題。 例如,當任何網站(任何博客)上的用戶將此字符串輸入輸入字段時。
<input name='msg' type='text' value='\x55'>
如何將此值編碼為原始的'\\ x55'我的意思是,任何特殊字符,不完全是十六進制
來自web.py框架的完整代碼
import web
ulrs = ('/reg', Reg)
class Reg:
def POST(self):
request = web.input(msg=None)
return request.msg
>>> U
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.