From 71f2e487514545a336f263abd0c2eff9ce7b79d3 Mon Sep 17 00:00:00 2001 From: tmeissner Date: Tue, 26 Aug 2014 13:44:55 +0200 Subject: [PATCH] new internal method _set_id() to set global last_id attribute to the highest id found in actual notebook object --- python_3_oop/chapter02/notebook.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/python_3_oop/chapter02/notebook.py b/python_3_oop/chapter02/notebook.py index 87c5042..eab627f 100644 --- a/python_3_oop/chapter02/notebook.py +++ b/python_3_oop/chapter02/notebook.py @@ -67,3 +67,11 @@ class Notebook: return note return None + def _set_id(self): + id = 1 + for note in self.notes: + if note.id > id: + id = note.id + global last_id + last_id = id +