首页 > 其他 > 详细

FTP-成型版本

时间:2017-08-10 12:43:37      阅读:170      评论:0      收藏:0      [点我收藏+]

1. 旧知识回顾-反射

hasattr(object, name)

说明:判断对象object是否包含名为name的属性(方法)

测试代码如下:

class tt(object):
    def __init__(self):
        pass

    def AA(self):
        self.name=‘Lucy‘
    def tes(self):
        while True:
            cmd=input(">>:").strip()
            if hasattr(self,cmd): #用来判断对象object的属性(name表示)是否存在。
                print(‘Yes,we have fun %s‘%cmd)
            else:
                print("nonono...,we don‘t have this fun")
obj=tt()
obj.tes()

运行结果:

 

>>:AA
Yes,we have fun AA
>>:test
nonono...,we don‘t have this fun
>>:b
nonono...,we don‘t have this fun
>>:

 

 

 

 

 

 

FTP-成型版本

原文:http://www.cnblogs.com/momo8238/p/7338348.html

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