Python OOP 메모장 만들기
class Note(object):
"""docstring for Note."""
def __init__(self, content = None):
super(Note, self).__init__()
self.content = content
def write_content(self, content):
self.content = content
def remove_all(self):
self.content = ""
def __str__(self):
return str(self.write_content)
class NoteBook(object):
"""docstring for NoteBook."""
def __init__(self, title):
super(NoteBook, self).__init__()
self.title = title
self.page_number = 1
self.notes = {}
def add_note(self, note, page =0):
if self.page_number < 300:
if page ==0:
self.notes[self.page_number] = note
self.page_number += 1
else:
self.notes = {page: note}
self.page_number += 1
else:
print("페이지가 모두 채워졌읍니다.")
def remove_note(self, page_number):
if page_number in self.notes.keys():
return self.notes.pop(page_number)
else:
print("해당 페이지는 존재하지 않습니다.")
def get_number_of_pages(self):
return len(self.notes.keys())
## note_user.py
from teamlab_note import NoteBook
from teamlab_note import Note
quote_book = NoteBook("The Quote Book")
new_note = Note()
new_note.write_content("Don't cry because it's over, because it happende. - Dr. Seuss")
quote_book.add_note(new_note)
print(quote_book.get_number_of_pages())
quote_book.add_note(Note("Hello, World"))
quote_book.add_note(Note("Hello, World"))
quote_book.add_note(Note("Hello, World"))
quote_book.add_note(Note("Hello, World"))
quote_book.add_note(Note("Hello, World"))
print(quote_book.get_number_of_pages())
my_note = quote_book.remove_note(1)
print(my_note)
my_note = quote_book.remove_note(1)
print(my_note)
'my_lesson > _Python' 카테고리의 다른 글
Python Java C - Vim을 IDE처럼 사용할수 있게 설정하기 (0) | 2018.09.28 |
---|---|
Python 가상환경 Miniconda 설치하기 Linux Windos Mac (0) | 2018.09.27 |
Python Objects in Python(파이썬에서의 객체) (0) | 2018.09.26 |
Python 아톰에서 실행방법 & 한글께짐 해결방법 (0) | 2018.09.26 |
Python Enumerate & Zip (0) | 2018.09.26 |
댓글