Tag: Log CLI Import interprets data string POS family data-
security substitution for string templates (Safe_substitute) specifically explained
This address: http://blog.csdn.net/caroline_wendy/article/details/27057339
string Template (Sting. Template), an exception occurs when replacing, using substitute (), fails to provide all of the parameters required for the templates.
Assuming that Safe_substitute (), or safe substitution, replaces the existing dictionary value, preserving the non-existent substitution symbol.
Code:
#-*-Coding:utf-8-*-' Created on 2014.5.26@author:c.l.wangeclipse Pydev python 2.7.5 ' import stringvalues = {' var ': ' foo '}t = string. The Template ("' $var are here but $ missing are not provided! Try: print ' Substitute (): ', T.substitute (values) except ValueError as err: print ' Error: ', str (ERR) print ' Safe_substitude (): ', T.safe_substitute (values)
Output:
Substitute (): error:invalid placeholder in String:line 1, col 18safe_substitude ():
Python-Security substitution for string templates (Safe_substitute) specifically explained