本文整理汇总了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)
示例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)
示例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'
示例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)