python 用twitter练习课程

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 用twitter练习课程相关的知识,希望对你有一定的参考价值。

#class practice questions
#This practice tests class organization and inheritance

class User:
	#base is the mother twitter instance
	def __init__(self, name):
		self.name = name
		
	def __repr__(self):
		return "({0})".format(self.name)
		
		
class Tweet:
	
	def __init__(self, user, message):
		self.user = user
		self.message = message
		
	def __repr__(self):
		return str(self.user) + "==\"{0}\"".format(self.message)
		
		
class Follow:
	
	def __init__(self, follower, user):
		self.follower = follower
		self.user = user
		
	def __repr__(self):
		return str(self.follower) + " --> " + str(self.user)
		

#all components of the twitter are stored in one class, while other classes 
#store specific components
class Twitter:
	
	def __init__(self):
		self.users = {}
		self.tweets = []
		self.follows = []
	
	def __repr__(self):
		return "USERS=[{0}]\nTWEETS=[{1}]\nFOLLOWS=[{2}]".format(self.users, self.tweets, self.follows)
		
	def create_follow(self, follower, user):
		self.follows.append(Follow(follower, user))
		
	def create_user(self, name):
		self.users[name] = User(name)
		
	def create_tweet(self, user, message):
		self.tweet.append(Tweet(user, message))
		
	

以上是关于python 用twitter练习课程的主要内容,如果未能解决你的问题,请参考以下文章

九Python+Selenium模拟用QQ登陆腾讯课堂,并提取报名课程(练习)

python练习——moudule03——选课系统

python练习第五天

SQL语法练习

Python全栈课程-第一章练习题-多用户登录(list和file的使用)

Python/ MySQL练习题