本文整理汇总了Python中textwrap.TextWrapper.subsequent_indent方法的典型用法代码示例。如果您正苦于以下问题:Python TextWrapper.subsequent_indent方法的具体用法?Python TextWrapper.subsequent_indent怎么用?Python TextWrapper.subsequent_indent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类textwrap.TextWrapper
的用法示例。
在下文中一共展示了TextWrapper.subsequent_indent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _stream_formatter
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_indent [as 别名]
def _stream_formatter(self, record):
"""The formatter for standard output."""
if record.levelno < logging.DEBUG:
print(record.levelname, end='')
elif(record.levelno < logging.INFO):
colourPrint(record.levelname, 'green', end='')
elif(record.levelno < IMPORTANT):
colourPrint(record.levelname, 'magenta', end='')
elif(record.levelno < logging.WARNING):
colourPrint(record.levelname, 'lightblue', end='')
elif(record.levelno < logging.ERROR):
colourPrint(record.levelname, 'brown', end='')
else:
colourPrint(record.levelname, 'red', end='')
if record.levelno == logging.WARN:
message = '{0}'.format(record.msg[record.msg.find(':')+2:])
else:
message = '{0}'.format(record.msg)
if len(message) > self.wrapperLength:
tw = TextWrapper()
tw.width = self.wrapperLength
tw.subsequent_indent = ' ' * (len(record.levelname)+2)
tw.break_on_hyphens = False
message = '\n'.join(tw.wrap(message))
print(': ' + message)
示例2: dump_recursive_parents
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_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))
示例3: do_me
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_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)
示例4: dump_recursive_comments
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_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)
示例5: wrap_for_make
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_indent [as 别名]
def wrap_for_make(items):
line = join(sorted(items))
wrapper = TextWrapper()
wrapper.width = 60
wrapper.break_on_hyphens = False
wrapper.subsequent_indent = '\t' * 2
return ' \\\n'.join(wrapper.wrap(line))
示例6: printHeader
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_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
示例7: CppInitializations
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_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))
示例8: CppEvaluations
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_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])
示例9: refill
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_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)
示例10: info
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_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
示例11: usage
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_indent [as 别名]
def usage(self):
tw = TextWrapper(
width=78,
drop_whitespace=True,
expand_tabs=True,
fix_sentence_endings=True,
break_long_words=True,
break_on_hyphens=True,
)
text = tw.fill(self.__doc__.strip()) + "\n\n"
try:
options = self.pluginOptions
except AttributeError:
return text + "This plugin does not support any options.\n"
tw.subsequent_indent=' ' * 16,
text += "Options supported by this plugin:\n"
for opt in sorted(options.keys()):
text += "--opt={:<12} ".format(opt)
text += tw.fill(options[opt].strip()) + "\n"
text += "\n"
text += "You can also chain options together, e.g.:\n"
text += " --opt=systems,stations,csvonly\n"
return text
示例12: list_posts
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_indent [as 别名]
def list_posts(discussions):
t = PrettyTable([
"identifier",
"title",
"category",
"replies",
# "votes",
"payouts",
])
t.align = "l"
t.align["payouts"] = "r"
# t.align["votes"] = "r"
t.align["replies"] = "c"
for d in discussions:
identifier = "@%s/%s" % (d["author"], d["permlink"])
identifier_wrapper = TextWrapper()
identifier_wrapper.width = 60
identifier_wrapper.subsequent_indent = " "
t.add_row([
identifier_wrapper.fill(identifier),
identifier_wrapper.fill(d["title"]),
d["category"],
d["children"],
# d["net_rshares"],
d["pending_payout_value"],
])
print(t)
示例13: default_attribute_formatter
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_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)
示例14: number_attribute_formatter
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_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)
示例15: header_attribute_formatter
# 需要导入模块: from textwrap import TextWrapper [as 别名]
# 或者: from textwrap.TextWrapper import subsequent_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)