本文整理汇总了Python中note.Note.parse_from_str方法的典型用法代码示例。如果您正苦于以下问题:Python Note.parse_from_str方法的具体用法?Python Note.parse_from_str怎么用?Python Note.parse_from_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类note.Note
的用法示例。
在下文中一共展示了Note.parse_from_str方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_notes
# 需要导入模块: from note import Note [as 别名]
# 或者: from note.Note import parse_from_str [as 别名]
def edit_notes(mn, config_store, args):
"""
Display search results and allow edits.
:param Mininote mn: Mininote instance
:param ConfigStore config_store: User configuration
:param argparse.Namespace args: Command line options
"""
from match_notes import match_notes
text_editor = args.text_editor
before_notes = list(mn.search(args.note))
before_formatted_notes = '\r\n'.join(map(str, before_notes))
after_formatted_notes = text_editor.edit(before_formatted_notes)
try:
nonblank_lines = filter(lambda line: len(line.strip()) > 0, after_formatted_notes.splitlines())
after_notes = map(Note.parse_from_str, nonblank_lines)
except NoteParseError:
logger.error("Unable to parse changes to notes. Session is saved in {}".format(text_editor.path))
return
text_editor.cleanup()
before_notes_reparsed = map(lambda n: Note.parse_from_str(str(n)), before_notes)
pairs = match_notes(before_notes_reparsed, after_notes)
for before, after in pairs:
if before is None:
mn.add_note(after_notes[after])
elif after is None:
mn.delete_note(before_notes[before])
elif before_notes[before].text != after_notes[after].text:
before_notes[before].text = after_notes[after].text
mn.update_note(before_notes[before])