
implementation of status.py in Facebook.py
By:
qflint on
May 16th, 2012 | syntax:
None | size: 1.73 KB | hits: 21 | expires: Never
class status:
#status( string, string, list-of-string, list-of-comment)
## initialize whoLiked and comments as empty strings
def __init__(self, whoPosted, status, whoLiked, comments):
self.whoPosted = whoPosted
self.status = status
self.whoLiked = whoLiked
self.comments = comments
### string! I need this....
#_str_: --> string
def __str__(self):
theLikes = ''
theComments = ''
length = len(self.whoLiked)
if length == 1:
if self.whoLiked != []:
theLikes = theLikes + self.whoLiked[0] + ' likes this.' + '\n'
elif length == 2:
if self.whoLiked != []:
theLikes = theLikes + self.whoLiked[0] + ' and ' + self.whoLiked[1] + ' like this.' + '\n'
elif length > 2:
for like in range(length-1):
theLikes = theLikes + self.whoLiked[like] + ', '
theLikes = theLikes + 'and ' + self.whoLiked[-1] + ' like this.' + '\n'
for aComment in self.getcomments():
theComments = theComments + str(aComment) + '\n'
return ( self.whoPosted + ' ' + self.status + '\n'
+ theLikes
+ theComments)
#### alright, so i want to use the __str__ below inside of my print line in the for loop
#viewstatus: --> status
def viewstatus(self):
if self.loggedIn.lstrip() != '':
listOfID = list(self.posts.keys())
listOfPosts = list(self.posts.values())
for aPost in range(len(listOfPosts)):
print ( '(' + str(listOfID[aPost]) + ')' +
str(listOfPosts[aPost]))