当前位置: 首页>>代码示例>>Python>>正文


Python Template.startswith方法代码示例

本文整理汇总了Python中string.Template.startswith方法的典型用法代码示例。如果您正苦于以下问题:Python Template.startswith方法的具体用法?Python Template.startswith怎么用?Python Template.startswith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在string.Template的用法示例。


在下文中一共展示了Template.startswith方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute

# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import startswith [as 别名]
    def execute(self):
        real_cmd = Template(self.command).substitute({
            'pathname': self.pathname,
            'name': os.path.basename(self.pathname),
            'path': os.path.dirname(self.pathname),
        })

        #如果命令以@开头, 则去掉@, 不输出命令.
        if real_cmd.startswith('@'):
            real_cmd = real_cmd[1:]
        else:
            print real_cmd

        os.system(real_cmd)
开发者ID:wonderbeyond,项目名称:inaction,代码行数:16,代码来源:inaction.py

示例2: source_url_and_member_name

# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import startswith [as 别名]
def source_url_and_member_name (get_fpath, variables):
	i = 1; member_name = None
	f = open (get_fpath, 'r')
	for line in f.readlines ():
		expanded_line = Template (line.rstrip ()).substitute (variables)
		if i == 1:
			source_url = expanded_line
		elif expanded_line.startswith ('get '):
			member_name = expanded_line [4:]
			member_name = member_name.strip ()
			break
		i = i + 1
	
	f.close	
	return (source_url, member_name)
开发者ID:finnianr,项目名称:Eiffel-Loop,代码行数:17,代码来源:package.py

示例3: write

# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import startswith [as 别名]
  def write (self, context, fname):
    if fname is None:
      fname = self.fname

    fname = Template (fname).safe_substitute (config)

    if fname.startswith ('/'):  # assume the caller know what they are doing, and it's a full path
      pth = fname
    else:
      pth = os.path.join (config.templates_path, fname)
      ensure_dirs (pth)

    content = context or self.content

    with open (pth, 'w') as f:
      f.write (content.encode ('UTF-8'))
      if trace: print fname, 'WRITE OK'
开发者ID:jowolf,项目名称:tlg,代码行数:19,代码来源:engine-pre-cleanup-020516.py

示例4: resolve_dependency_parameters

# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import startswith [as 别名]
 def resolve_dependency_parameters(self, dependency_parameters, inherited_parameters):
   templated_params = {}
   for key, value in dependency_parameters.items():
     try:
       value = Template(value).substitute(inherited_parameters)
     except KeyError, e:
       print "Could not resolve template parameter", e
       raise
     if not value.startswith("="):
       templated_params[key] = templated_params.get(key, []) + [value]
     else:
       eval_value = eval(value[1:])
       if isinstance(eval_value, basestring):
         templated_params[key] = templated_params.get(key, []) + [eval_value]
       elif hasattr(eval_value, "__iter__"):
         for v in eval_value:
           templated_params[key] = templated_params.get(key, []) + [v]
       else:
         raise "Unable to handle evalutation of parameter, must be string or iterable: %s = %s" % (key, eval_value)
开发者ID:songkick,项目名称:datamake,代码行数:21,代码来源:datamake_legacy.py


注:本文中的string.Template.startswith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。