本文整理汇总了Python中formatter.Formatter.beautify方法的典型用法代码示例。如果您正苦于以下问题:Python Formatter.beautify方法的具体用法?Python Formatter.beautify怎么用?Python Formatter.beautify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类formatter.Formatter
的用法示例。
在下文中一共展示了Formatter.beautify方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import beautify [as 别名]
def main():
"""
Get all questions, for each question get all the answers.
:return:
"""
print '|Getting questions from Stackoverflow. Please wait...|'
items = list()
questions = get_questions()
print '|Total questions: {} |'.format(len(questions))
if questions:
for question in questions:
formatter = Formatter()
question.body = get_question_body(question.id)
question.body_clean = formatter.beautify(question.body)
question.answers = get_answers(question.id) # Iterate over each question and get all answers
print '|Display information'
for question in questions:
item = Item()
if question.title and question.body_clean:
item.text = question.title + ' ' + question.body_clean
if question.answers:
for answer in question.answers:
item.text += ' ' + answer.body_clean
item.text.rstrip('\r\n')
items.append(item)
print '<<'
print item.text
示例2: process_answer_items
# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import beautify [as 别名]
def process_answer_items(content, beautify=True):
"""
Process response and generate dictionary with questions and URL
:param content:
:param beautify:
:return:
"""
answers = list()
if "items" in content:
items = content["items"]
for item in items:
answer = Answer()
answer.id = item['answer_id']
answer.body = item['body']
answer.is_accepted = item['is_accepted']
if beautify:
formatter = Formatter()
answer.body_clean = formatter.beautify(answer.body)
answers.append(answer)
return answers