Python-Security substitution for string templates (Safe_substitute) specifically explained

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.