提交 40828965 authored 作者: Ian Goodfellow's avatar Ian Goodfellow

pep8 and doc

上级 9b9b76d7
def renderString(string, dict):
import warnings
def render_string(string, sub):
"""
string: a string, containing formatting instructions
sub: a dictionary containing keys and values to substitute for
them.
returns: string % sub
The only difference between this function and the % operator
is that it raises an exception with a more informative error
message than the % operator does.
"""
try:
finalCode = string % dict
finalCode = string % sub
except Exception , E:
#print 'could not render C code due to exception with message "'+str(E)+'", trying to find out why...'
# If unable to render the string, render longer and longer
# initial substrings until we find the minimal initial substring
# that causes an error
i = 0
while i <= len(string):
try:
finalCode = string[0:i] % dict
finalCode = string[0:i] % sub
except Exception, F:
if str(F) == str(E):
raise Exception(string[0:i]+"<<<< caused exception "+str(F))
i+=1
assert False
return finalCode
#
def renderString(string, dict):
warnings.warn("renderString is deprecated. It is now called render_string",
stack_level = 2)
return render_string(string, dict)
def pretty_format(string):
lines = string.split('\n')
......@@ -34,11 +53,8 @@ def pretty_format(string):
rval = '\n'.join(lines)
return rval
#
def strip_leading_white_space(line):
while len(line) >0 and (line[0]==' ' or line[0]=='\t'):
line = line[1:]
#
return line
#
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论