Research on dynamic parametric names of Python and Saltstack

Source: Internet
Author: User
Tags saltstack

python Dynamic Variable name

 import   Syscreatevar  = locals () listtemp  = range (1,10 for  i in  range (1 Span style= "color: #0000ff;" >print   Sys.argv[i] A, b  = Sys.argv[i].split (   =    ) Createvar[a]  = b  print   get=   ", Get,"  put=   ", put 

It is worth noting that, with the python dynamic variable name This function, the external incoming parameters can not be the same as the variable name defined inside the code, otherwise it will cause the variable cross-read error, resulting in a code error and throw a variable can not read the exception, the reason is unknown, need to parse the source of Python underlying library

Workaround: Define extremely perverted variable names in Python code, and never enter them when external parameters are passed in.

Saltstack provides a range of methods internally, so just write a module,module with the following methods:

def Test (* *Kwargs)    : param=kwargs['__pub_arg'][0]    kw = for in      param.items ():        kw[d]=x    return kw

Research on dynamic parametric names of Python and Saltstack

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.