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


Python Notebook.create_note方法代码示例

本文整理汇总了Python中notebook.Notebook.create_note方法的典型用法代码示例。如果您正苦于以下问题:Python Notebook.create_note方法的具体用法?Python Notebook.create_note怎么用?Python Notebook.create_note使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在notebook.Notebook的用法示例。


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

示例1: __init__

# 需要导入模块: from notebook import Notebook [as 别名]
# 或者: from notebook.Notebook import create_note [as 别名]
class Menu:
	"""
	Represent a command-line user interface for Notebook application.
	"""

	def __init__(self):
		self.notebook = Notebook()
		self.choices = OrderedDict.fromkeys('12345')
		self.choices['1'] = {'display': 'Show notes',
							 'handler': self.show_notes}
		self.choices['2'] = {'display': 'Search notes',
							 'handler': self.search_notes}
		self.choices['3'] = {'display': 'Add notes',
							 'handler': self.add_note}
		self.choices['4'] = {'display': 'Modify notes',
							 'handler': self.modify_note}
		self.choices['5'] = {'display': 'Quit',
							 'handler': self.quit}

	def display_menu(self):
		"""
		Display the Notebook application's menu.
		"""
		print('==================')
		for k, v in self.choices.items():
			print(k, v.get('display'))

		choice = input('What do you want to do? ')
		action = self.choices.get(choice)

		if action:
			handler = action.get('handler')
			handler()
		else:
			print(choice, 'is not a valid choice')

	def run(self):
		"""
		Run the application: display the menu and respond to user's choice.
		"""
		while True:
			self.display_menu()
			pass

	def show_notes(self, notes=None):
		"""
		Display all notes in the notebook.
		"""

		if notes is None:
			notes = self.notebook.notes

		if len(notes) > 0:
			for note in notes:
				print(note, '\r\n')
		else:
			print("No note matches.")

	def search_notes(self):
		"""
		Search for a note in the notebook (by its content and tags).
		"""
		search_string = input('You want to search for ...? ')
		filtered_notes = self.notebook.search(search_string)
		self.show_notes(filtered_notes)

	def add_note(self):
		"""
		Add a new note to the notebook.
		"""
		memo = input('Enter the memo: ')
		tags = input('Enter the tags (separated by commas): ')
		self.notebook.create_note(memo, tags)
		print('Your note has been created.')

	def modify_note(self):
		"""
		Modify a note in the notebook.
		"""
		note_id = input('Enter the note id: ')
		note = self.notebook.find_note_by_id(note_id)

		if note is None:
			print('No note matches.')
		else:
			memo = input('Enter the new memo: ')
			tags = input('Enter the new tags (separated by commas): ')

			if memo:
				note.memo = memo

			if tags:
				note.tags = tags

	def quit(self):
		"""
		Exit the application.
		"""
		print("Thank you for using Notebook application.")
		sys.exit(0)
开发者ID:sonhuytran,项目名称:Learning.Python,代码行数:102,代码来源:menu.py


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