本文整理汇总了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))
示例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
示例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']))
示例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)
示例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)
示例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()
示例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!!")
示例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()
示例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()
示例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)
示例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()
示例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 []
示例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']))
示例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()
示例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()