本文整理汇总了Python中textwrap.TextWrapper.initial_indent方法的典型用法代码示例。如果您正苦于以下问题:Python TextWrapper.initial_indent方法的具体用法?Python TextWrapper.initial_indent怎么用?Python TextWrapper.initial_indent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类textwrap.TextWrapper
的用法示例。
在下文中一共展示了TextWrapper.initial_indent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __str__
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def __str__(self):
if self.networks and len(self.networks) > 1:
lines = ["Nexus dataset '%s' (#%s) with %d networks" % \
(self.sid, self.id, len(self.networks))]
else:
lines = ["Nexus dataset '%(sid)s' (#%(id)s)" % self.__dict__]
lines.append("vertices/edges: %s" % self.vertices_edges)
if self.name:
lines.append("name: %s" % self.name)
if self.tags:
lines.append("tags: %s" % "; ".join(self.tags))
if self.rest:
wrapper = TextWrapper(width=76, subsequent_indent=' ')
keys = sorted(self.rest.iterkeys())
if "attribute" in self.rest:
keys.remove("attribute")
keys.append("attribute")
for key in keys:
for value in self.rest.getlist(key):
paragraphs = str(value).splitlines()
wrapper.initial_indent = "%s: " % key
for paragraph in paragraphs:
ls = wrapper.wrap(paragraph)
if ls:
lines.extend(wrapper.wrap(paragraph))
else:
lines.append(" .")
wrapper.initial_indent = " "
return "\n".join(lines)
示例2: CppEvaluations
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def CppEvaluations(self, Indent=4):
"""Evaluate all derived variables in C++
This function uses the `substitution` expressions for the
derived variables. This output is appropriate for updating
the values of the variables at each step of an integration,
for example.
"""
from textwrap import TextWrapper
wrapper = TextWrapper(width=120)
wrapper.initial_indent = ' '*Indent
wrapper.subsequent_indent = wrapper.initial_indent + ' '
def Evaluation(atom):
def Ccode(a) :
try:
return a.ccode()
except :
from sympy.printing import ccode
return ccode(a)
if atom.datatype and (atom.datatype=='std::vector<double>' or atom.datatype=='std::vector<std::complex<double> >') :
return '\n'.join([wrapper.fill('{0}[{1}] = {2};'.format(self.Variables[atom], i, Ccode(atom.substitution[i])))
for i in range(len(atom.substitution))])
else:
return wrapper.fill('{0} = {1};'.format(self.Variables[atom], atom.ccode()))
return '\n'.join([Evaluation(atom) for atom in self.Atoms if not atom.fundamental and not atom.constant])
示例3: CppInitializations
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def CppInitializations(self, Indent=4):
"""Create initialization list for C++
For example, if the `Variables` object contains atoms m1, m2,
t, and x referred to in the `Expressions` object, where m1 and
m2 are constant, and t and x are variables, the initialization
list should be
m1(m1_i), m2(m2_i), t(t_i), x(x_i)
The quantities m1_i, etc., appear in the input-argument list
output by the method `CppInputArguments`.
"""
from textwrap import TextWrapper
wrapper = TextWrapper(width=120)
wrapper.initial_indent = ' '*Indent
wrapper.subsequent_indent = wrapper.initial_indent
def Initialization(atom):
if atom.datatype and (atom.datatype=='std::vector<double>' or atom.datatype=='std::vector<std::complex<double> >'):
return '{0}({1})'.format(self.Variables[atom], len(atom.substitution))
if atom.fundamental:
return '{0}({0}_i)'.format(self.Variables[atom])
else:
return '{0}({1})'.format(self.Variables[atom], atom.ccode())
Initializations = [Initialization(atom) for atom in self.Atoms]
return wrapper.fill(', '.join(Initializations))
示例4: dump_recursive_parents
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def dump_recursive_parents(rpc,
post_author,
post_permlink,
limit=1,
format="markdown"):
global currentThreadDepth
limit = int(limit)
postWrapper = TextWrapper()
postWrapper.width = 120
postWrapper.initial_indent = " " * (limit)
postWrapper.subsequent_indent = " " * (limit)
if limit > currentThreadDepth:
currentThreadDepth = limit + 1
post = rpc.get_content(post_author, post_permlink)
if limit and post["parent_author"]:
parent = rpc.get_content_replies(post["parent_author"], post["parent_permlink"])
if len(parent):
dump_recursive_parents(rpc, post["parent_author"], post["parent_permlink"], limit - 1)
meta = {}
for key in ["author", "permlink"]:
meta[key] = post[key]
meta["reply"] = "@{author}/{permlink}".format(**post)
if format == "markdown":
body = markdownify(post["body"])
else:
body = post["body"]
yaml = frontmatter.Post(body, **meta)
print(frontmatter.dumps(yaml))
示例5: info
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def info(cls, _str=True):
if not _str:
return PCFGConfig.argNames
# Auto text wrapper to output the doc.
tw = TextWrapper()
tw.initial_indent = " "
tw.subsequent_indent = " "
retVal = "General Configuration: \n"
for argName in PCFGConfig.argNames:
arg = str(argName["arg"])
argreq = str(argName["req"])
argtype = str(argName["type"].__name__)
argdef = str(argName["def"])
argdoc = str(argName["doc"])
argex = str(argName["ex"])
doclines = tw.wrap(argdoc)
aType = "optional"
if argreq:
aType = "required"
retVal += " %s (%s, %s):\n" % (arg, argtype, aType)
retVal += " Defaults to %s\n" % (argdef)
for docline in doclines:
retVal += "%s\n" % docline
retVal += " Example: %s\n" % argex
retVal += "\n"
return retVal
示例6: dump_recursive_comments
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def dump_recursive_comments(rpc,
post_author,
post_permlink,
depth=0,
format="markdown"):
global currentThreadDepth
postWrapper = TextWrapper()
postWrapper.width = 120
postWrapper.initial_indent = " " * (depth + currentThreadDepth)
postWrapper.subsequent_indent = " " * (depth + currentThreadDepth)
depth = int(depth)
posts = rpc.get_content_replies(post_author, post_permlink)
for post in posts:
meta = {}
for key in ["author", "permlink"]:
meta[key] = post[key]
meta["reply"] = "@{author}/{permlink}".format(**post)
if format == "markdown":
body = markdownify(post["body"])
else:
body = post["body"]
yaml = frontmatter.Post(body, **meta)
print(frontmatter.dumps(yaml))
reply = rpc.get_content_replies(post["author"], post["permlink"])
if len(reply):
dump_recursive_comments(rpc, post["author"], post["permlink"], depth + 1)
示例7: refill
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def refill(msg):
"""
Refill a changelog message.
Normalize the message reducing multiple spaces and newlines to single
spaces, recognizing common form of ``bullet lists``, that is paragraphs
starting with either a dash "-" or an asterisk "*".
"""
wrapper = TextWrapper()
res = []
items = itemize_re.split(msg.strip())
if len(items)>1:
# Remove possible first empty split, when the message immediately
# starts with a bullet
if not items[0]:
del items[0]
if len(items)>1:
wrapper.initial_indent = '- '
wrapper.subsequent_indent = ' '*2
for item in items:
if item:
words = filter(None, item.strip().replace('\n', ' ').split(' '))
normalized = ' '.join(words)
res.append(wrapper.fill(normalized))
return '\n\n'.join(res)
示例8: printHeader
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def printHeader(s, level=1, length=70, prefix='# <Menotexport>:'):
from textwrap import TextWrapper
decs={1: '=', 2: '-', 3: '.'}
indents={1: 0, 2: 4, 3: 8}
dec=decs[level]
ind=indents[level]
indstr=' '*int(ind)
wrapper=TextWrapper()
wrapper.width=length-ind
wrapper.initial_indent=indstr
wrapper.subsequent_indent=indstr
#-------------Get delimiter line-------------
hline='%s%s' %(' '*int(ind),dec*int(length-ind))
#--------------------Wrap texts--------------------
strings=wrapper.wrap('%s %s' %(prefix,s))
#----------------------Print----------------------
try:
print('\n'+hline)
except:
print('\n'+hline.encode('ascii','replace'))
for ss in strings:
try:
print(ss)
except:
print(ss.encode('ascii','replace'))
#print(hline)
return
示例9: do_me
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def do_me(self,mdig_model):
from textwrap import TextWrapper
import re
models = mdig.repository.get_models()
title_str = "Models in MDiG GRASS db @ " + mdig.repository.db
print "-"*len(title_str)
print title_str
print "model_name [location]"
print " description"
print "-"*len(title_str)
ms=models.keys()[:]
ms.sort()
for m in ms:
try:
dm = DispersalModel(models[m],setup=False)
tw = TextWrapper(expand_tabs = False, replace_whitespace = True )
tw.initial_indent = " "*4
tw.subsequent_indent = " "*4
desc = dm.get_description()
desc = re.sub("[\\s\\t]+"," ",desc)
desc = tw.fill(desc)
loc = dm.get_location()
if not loc:
loc = dm.infer_location()
if not loc:
loc = "unknown"
print "%s [%s]:\n%s" % (m,loc,desc)
except mdig.model.ValidationError:
print "%s [ERROR]" % (m,)
sys.exit(0)
示例10: default_attribute_formatter
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def default_attribute_formatter(self, key, value):
wrapper = TextWrapper()
wrapper.initial_indent='FT '
wrapper.subsequent_indent='FT '
wrapper.width=79
attribute_text_template='/{attribute_key}="{attribute_value}"'
attribute_text=attribute_text_template.format(attribute_key=key, attribute_value=value)
return wrapper.fill(attribute_text)
示例11: plot_list
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def plot_list(self):
"""Lists the names of the available figures"""
wrapper = TextWrapper(subsequent_indent=" " * 22,
width=78)
for method, func in self.get_available_figures():
if method != "list":
wrapper.initial_indent = ("%-20s " % method).ljust(22)
print(wrapper.fill(func.figure_name))
示例12: number_attribute_formatter
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def number_attribute_formatter(self, key, value):
# transl_table attributes do not have their values in quotes
wrapper = TextWrapper()
wrapper.initial_indent='FT '
wrapper.subsequent_indent='FT '
wrapper.width=79
attribute_text_template='/{attribute_key}={attribute_value}'
attribute_text=attribute_text_template.format(attribute_key=key, attribute_value=value)
return wrapper.fill(attribute_text)
示例13: product_attribute_formatter
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def product_attribute_formatter(self, key, value):
# Products can include very long enzyme names which we don't want to break
wrapper = TextWrapper()
wrapper.initial_indent='FT '
wrapper.subsequent_indent='FT '
wrapper.width=79
wrapper.break_on_hyphens=True
attribute_text_template='/{attribute_key}="{attribute_value}"'
attribute_text=attribute_text_template.format(attribute_key=key, attribute_value=value)
return wrapper.fill(attribute_text)
示例14: header_attribute_formatter
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def header_attribute_formatter(self, key, header_text, quote_character, final_character):
wrapper = TextWrapper()
wrapper.initial_indent=key + ' '
wrapper.subsequent_indent=key + ' '
wrapper.width=79
attribute_text_template='{attribute_quote_character}{attribute_header_text}{attribute_quote_character}{attribute_final_character}'
attribute_text=attribute_text_template.format(attribute_header_text = header_text,
attribute_quote_character = quote_character,
attribute_final_character = final_character)
return wrapper.fill(attribute_text)
示例15: CppDeclarations
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import initial_indent [as 别名]
def CppDeclarations(self, Indent=4):
"""Create declaration statements for C++
For example, if the `Variables` object contains atoms m1, m2,
t, and x referred to in the `Expressions` object, where m1 and
m2 are constant, and t and x are variables, the declaration
list should be
const double m1, m2;
double t, x;
The code knows which atoms need to be declared at the
beginning, and which ones should be `const`, for example. For
C++, the default datatype is `double`; if the atom was created
with a different datatype, that will be used appropriately.
"""
from textwrap import TextWrapper
wrapper = TextWrapper(width=120)
wrapper.initial_indent = ''
wrapper.subsequent_indent = ''
datatype = ''
Declarations = ''
Names = []
for atom in self.Atoms:
thisdatatype = CodeConstructor.const(atom) + CodeConstructor.dtype(atom) + ' '
if thisdatatype != datatype:
if Names:
Declarations += wrapper.fill(', '.join(Names)) + ";\n"
Names = []
datatype = thisdatatype
wrapper.initial_indent = ' '*Indent + thisdatatype
wrapper.subsequent_indent = ' '*len(wrapper.initial_indent)
Names.append(self.Variables[atom])
if Names:
Declarations += wrapper.fill(', '.join(Names)) + ";\n"
return Declarations.rstrip()