-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlog.py
More file actions
33 lines (31 loc) · 744 Bytes
/
Blog.py
File metadata and controls
33 lines (31 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Post:
def __init__(self,content,author):
self.content = content
self.author = author
def __repr__(self):
return '<'+self.author+'>'+self.content
def __lt__(self,other):
return self.author < other.author
class Blog:
def __init__(self):
self.posts = []
def add_post(self,post):
self.posts.append(post)
def __repr__(self):
s=""
for post in self.posts:
s += str(post)+'\n'
return s.rstrip()
def sort(self):
self.posts.sort()
p1=Post("Horse","Ma")
p2=Post("Dog","Liu")
p3=Post("Chicken","Ning")
blog = Blog()
blog.add_post(p1)
blog.add_post(p2)
blog.add_post(p3)
print blog
print '-----------'
blog.sort()
print blog