Changes between Version 7 and Version 8 of GenshiTutorial
- Timestamp:
- Aug 29, 2007, 12:47:51 PM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
GenshiTutorial
v7 v8 187 187 self.comments = [] 188 188 189 def __repr__(self): 190 return '<%s %r>' % (type(self).__name__, self.title) 191 189 192 def add_comment(self, username, content): 190 self.comments.append(Comment(username, content)) 193 comment = Comment(username, content, in_reply_to=self) 194 self.comments.append(comment) 195 return comment 191 196 192 197 … … 200 205 self.replies = [] 201 206 207 def __repr__(self): 208 return '<%s>' % (type(self).__name__) 209 202 210 def add_reply(self, username, content): 203 self.replies.append(Comment(username, content, in_reply_to=self)) 211 reply = Comment(username, content, in_reply_to=self) 212 self.replies.append(reply) 213 return reply 204 214 }}} 205 215 … … 220 230 >>> data 221 231 [] 222 >>> s1 = Submission(username='joe', url='http://example.org/', title='An example') 223 >>> s2 = Submission(username='annie', url='http://reddit.com/', title='The real thing') 224 >>> data.append(s1) 225 >>> data.append(s2) 226 >>> s1.add_comment(username='jack', content='Bla bla bla') 227 >>> s1.comments[0].add_reply(username='joe', content='Bla blabla bla bla bla') 232 >>> submission = Submission(username='joe', url='http://example.org/', title='An example') 233 >>> comment = submission.add_comment(username='jack', content='Bla bla bla') 234 >>> comment.add_reply(username='joe', content='Bla blabla bla bla bla') 235 >>> data.append(submission) 236 >>> submission = Submission(username='annie', url='http://reddit.com/', title='The real thing') 237 >>> data.append(submission) 238 >>> data 239 [<Submission 'An example'>, <Submission 'The real thing'>] 228 240 >>> pickle.dump(data, open('geddit.db', 'wb')) 229 241 >>> ^D