当前位置: 首页>>代码示例>>Python>>正文


Python Formatter.beautify方法代码示例

本文整理汇总了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
开发者ID:spicyramen,项目名称:stackoverflowtagger,代码行数:32,代码来源:main.py

示例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
开发者ID:spicyramen,项目名称:stackoverflowtagger,代码行数:22,代码来源:main.py


注:本文中的formatter.Formatter.beautify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。