首页 > 编程语言 > 详细

[Python]Understand attribute in Python

时间:2014-09-21 12:44:41      阅读:353      评论:0      收藏:0      [点我收藏+]

This recipe is a small code snippet of showing how to distinguish attribute and item in Python language.

class MyClass(object):

	def __getitem__(self, name):
		return "this is from get item function"
	pass
	
def action():
	return "play basketball this afternoon"	
	
	
if __name__ == "__main__":

	me = MyClass()
	setattr(me,"weather","it is sunshine")
	setattr(me,"event",action)

	print me.weather
	print me['event']
	print me.event()

 

[Python]Understand attribute in Python

原文:http://blog.csdn.net/wonderfan/article/details/39450239

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!