码迷,mamicode.com
首页 > 编程语言 > 详细

[Python]Understand attribute in Python

时间:2014-09-21 13:03:30      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:python   object   

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

标签:python   object   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!