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


Python formatter.Formatter类代码示例

本文整理汇总了Python中formatter.Formatter的典型用法代码示例。如果您正苦于以下问题:Python Formatter类的具体用法?Python Formatter怎么用?Python Formatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Formatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: print_progress

 def print_progress(self):
     print("Average tfidf: " + str(1 - self.sum_tfidf / self.queries_asked))
     print("Average ngram-perplexity: " + str(self.sum_ngp / self.sentences_asked))
     print("Average edit-distance: " + str(self.sum_edit / self.queries_asked))
     print("Accept percent by tfidf extractor: " + Formatter.percent(self.accepted_by_tfidf / self.sentences_asked))
     print("Accept percent by ngram-perplexity extractor: " + Formatter.percent(self.accepted_by_ngp / self.sentences_asked))
     print("Accept percent by edit-distance extractor: " + Formatter.percent(self.accepted_by_edit_distance / self.sentences_asked))
开发者ID:EdwardBetts,项目名称:Text-Corpora-Adaptation-Tool,代码行数:7,代码来源:domainsimilarity.py

示例2: main

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,代码行数:30,代码来源:main.py

示例3: update

	def update(self, server, monitor, data):
		# clone monitor so we don't overwrite settings
		_monitor = dict(monitor)

		# TODO: delete monitor
		# skip empty monitor
		if not _monitor['alliances']: return

		logging.info("Sending Updates to chat %s", monitor['chatname'])

		# filter updates, conquers, and changes per this monitor
		_monitor['updates'] = {k: data['updates'][str(k)] for k in _monitor['alliances'] if data['updates'][str(k)] != None}
		_monitor['conquers'] = {k: data['conquers'][str(k)] for k in _monitor['alliances'] if data['conquers'][str(k)] != None}
		_monitor['changes'] = {k: data['changes'][str(k)] for k in _monitor['alliances'] if data['changes'][str(k)] != None}

		# get chat for monitor
		chat = self._skype.Chat(monitor['chatname'])
		
		# send updates to chat
		if (_monitor['updates']):
			chat.SendMessage(Formatter.format_updates(server, _monitor['updates']))
		if (_monitor['conquers']):
			chat.SendMessage(Formatter.format_conquers(server, _monitor['conquers']))
		if (_monitor['changes']):
			chat.SendMessage(Formatter.format_changes(server, _monitor['changes']))
开发者ID:briantanner,项目名称:Grepobot.py,代码行数:25,代码来源:monitor.py

示例4: SnorePlugin

class SnorePlugin(nose.plugins.Plugin):    
    """Enable Snarl notifications"""
    
    enabled = False
    name = "snore"
    score = 1
    
    def __init__(self, snarler, clock):
        super(SnorePlugin, self).__init__()
        self._formatter = Formatter(self._get_path('icons/'))
        self._snarler = snarler
        self._clock = clock
        
    def begin(self):
        self._start_time = self._clock.now()
        
    def finalize(self, result):
        counts = self._get_counts(result)
        title, icon = self._formatter.format_result(*counts)
        body = self._formatter.format_time(self._clock.now() - self._start_time)
        self._snarler.snarl(title, body, icon)
    
    def _get_counts(self, result):
        return (result.testsRun, len(result.failures), len(result.errors))
        
    def _get_path(self, filename):
        return pkg_resources.resource_filename('snore', filename)
开发者ID:jonspeicher,项目名称:snore,代码行数:27,代码来源:plugin.py

示例5: generate

    def generate(self, save=True):
        "Generates photo file in current format"
        crop_box = None
        if self.crop_left:
            crop_box = (self.crop_left, self.crop_top, \
                    self.crop_left + self.crop_width, self.crop_top + self.crop_height)

        important_box = None
        if self.photo.important_top is not None:
            p = self.photo
            important_box = (p.important_left, p.important_top, p.important_right, p.important_bottom)

        formatter = Formatter(Image.open(self.photo.image.path), self.format, crop_box=crop_box, important_box=important_box)

        stretched_photo, crop_box = formatter.format()

        self.crop_left, self.crop_top, right, bottom = crop_box
        self.crop_width = right - self.crop_left
        self.crop_height = bottom - self.crop_top

        self.width, self.height = stretched_photo.size
        stretched_photo.save(self.file(), quality=self.format.resample_quality)

        f = open(self.file())
        file = ContentFile(f.read())
        f.close()

        self.image.save(self.file(relative=True), file, save)
开发者ID:chewable,项目名称:ella,代码行数:28,代码来源:models.py

示例6: formatMethods

def formatMethods(namespace):
    formatter = Formatter(METHOD_INDENTATION)
    for method in namespace['methods']:
        formatter.add(generateMethodJSDoc(method))
        formatter.addLine('this.', convertIds(method['name']), ' = function(', formatParams(method['parameters']), ") {")
        formatter.addLine('};')
        formatter.newLine()
    return formatter.getResult()
开发者ID:pchlupacek,项目名称:jsca2js,代码行数:8,代码来源:jsca2js.py

示例7: delete_branches

 def delete_branches(self, remote=False):
     """Delete the branches."""
     """If Remote=True, deletes remote branches as well."""
     if len(self.branches_to_be_deleted()) > 0:
         self.delete_local_branches()
         if remote:
             self.delete_remote_branches()
         Formatter.print_pretty_ok_message("Cleaned Successfully!!")
开发者ID:gauravmanchanda,项目名称:Git-Janitor,代码行数:8,代码来源:worker.py

示例8: formatGlobal

def formatGlobal(namespace):
    formatter = Formatter(METHOD_INDENTATION)

    for method in namespace['methods']:
        formatter.add(generateMethodJSDoc(method))
        formatter.addLine('function ', convertKey(method['name']), '(', formatParams(method['parameters']), ") {")
        formatter.addLine('}')
        formatter.newLine()
    return formatter.getResult()
开发者ID:Tsuguya,项目名称:jsca2js,代码行数:9,代码来源:jsca2js.py

示例9: extendGlobal

def extendGlobal(name, namespace):
    formatter = Formatter(METHOD_INDENTATION)

    for method in namespace['methods']:
        formatter.add(generateMethodJSDoc(method))
        formatter.addLine(name, '.prototype.', convertKey(method['name']), ' = function(', formatParams(method['parameters']), ") {")
        formatter.addLine('};')
        formatter.newLine()
    return formatter.getResult()
开发者ID:Tsuguya,项目名称:jsca2js,代码行数:9,代码来源:jsca2js.py

示例10: main

def main():
	lines = []
	for line in fileinput.input():
		lines.append(line)
	f = Formatter(lines)
	lines = f.get_lines()

	for l in lines:
		print (l)
开发者ID:cwins0r,项目名称:sample-code,代码行数:9,代码来源:sengfmt2.py

示例11: formatMethods

def formatMethods(namespace):
    formatter = Formatter(METHOD_INDENTATION)
    key = 'methods' if 'methods' in namespace else 'method'
    for method in namespace[key]:
        formatter.add(generateMethodJSDoc(method))
        formatter.addLine(convertKey(method['name']), ':function(', formatParams(method['parameters']), ") {")
        formatter.addLine('},')
        formatter.newLine()
    return formatter.getResult()
开发者ID:Tsuguya,项目名称:jsca2js,代码行数:9,代码来源:jsca2js.py

示例12: branches_to_be_deleted

 def branches_to_be_deleted(self):
     """Return branches to be deleted."""
     branches = self.branches_to_be_deleted_excluding_skipped()
     if len(branches) > 0:
         Formatter.print_pretty_warn_message("Following local branches would \
             be deleted:")
         return branches
     else:
         Formatter.print_pretty_fail_message("No branches to be deleted")
         return []
开发者ID:gauravmanchanda,项目名称:Git-Janitor,代码行数:10,代码来源:worker.py

示例13: test_format_all

 def test_format_all(self):
   text = '''
   I HATE JUSTIN BIEBER comedy 
   I LOVE JUSTIN BIEBER comedy 
   JUSTIN BIEBER WEDDING comedy 
   JUSTIN BIEBER HAIR SOS 83 actress albino squirrel bored brittani taylor comedy entertainment fun funky funny happy hollywood hot justin bieber love missal random series sexy shout out sunday show silly sketch vampire vampires weekly 
   IS JUSTIN BIEBER CREEPY OR ADORABLE What Really Happened To Tiger Woods Criminal Names comedy newsinformation 
   Lady Gaga Alejandro Video Eats Rosary Miley Cyrus NO HOMO Spellbound Wins BGT comedy newsinformation 
   Black Eyed Peas on winning their 2nd consecutive AMA 2010 abc aguilera american awards bieber black bon christina clark dick diddy diddydirty dirty divorce dream enrique eyed iglesias jovi justin katy milian money music peas perry pink productions rihanna talkinterview tay the usher 
   '''
   formatter = Formatter(text, "\n")
   words = formatter.run_all()
   expect(words).to.equal(set(['hate justin bieber comedy', 'black eyed peas winning their consecutive aguilera american awards bieber black christina clark dick diddy diddydirty dirty divorce dream enrique eyed iglesias jovi justin katy milian money music peas perry pink productions rihanna talkinterview usher', 'justin bieber creepy adorable what really happened tiger woods criminal names comedy newsinformation', 'lady gaga alejandro video eats rosary miley cyrus homo spellbound wins comedy newsinformation', 'justin bieber hair actress albino squirrel bored brittani taylor comedy entertainment funky funny happy hollywood justin bieber love missal random series sexy shout sunday show silly sketch vampire vampires weekly', 'love justin bieber comedy', 'justin bieber wedding comedy']))
开发者ID:UMNLibraries,项目名称:hamster,代码行数:13,代码来源:test_formatter.py

示例14: formatProperties

def formatProperties(namespace):
    formatter = Formatter(METHOD_INDENTATION)
    for property in namespace['properties']:
        formatter.add(generatePropertyJSDoc(property))
        formatter.addLine(convertKey(property['name']), ':null,')
        formatter.newLine()
    return formatter.getResult()
开发者ID:Tsuguya,项目名称:jsca2js,代码行数:7,代码来源:jsca2js.py

示例15: _generate_img

    def _generate_img(self):
        crop_box = None
        if self.crop_left:
            crop_box = (self.crop_left, self.crop_top, \
                    self.crop_left + self.crop_width, self.crop_top + self.crop_height)

        important_box = None
        if self.photo.important_top is not None:
            p = self.photo
            important_box = (p.important_left, p.important_top, p.important_right, p.important_bottom)

        formatter = Formatter(self.photo._get_image(), self.format, crop_box=crop_box, important_box=important_box)

        return formatter.format()
开发者ID:andymccurdy,项目名称:ella,代码行数:14,代码来源:models.py


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