Monday, April 21, 2014

'__setattr__' ,


class FlumeEnv(object): # use a class to check flume environment def __init__(self, zk_ip): self._zk_ip = zk_ip def check(self): flag = True # run all method statswith '_check' def _check_zk_connection(self): try: telnetlib.Telnet(self._zk_ip, rev check 2181, 5) return True except: return False def _check_java_home(self): return True if 'JAVA_HOME' in os.environ else False
class FlumeEnv ( object ) :
google了下找到了解决方法 其中用到了dir和getattr
In [79]: dir(a) Out[79]: ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', rev check '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_foo2', 'foo'] In [80]: [i for i in dir(a) if i.startswith('foo')][0] Out[80]: 'foo' In [81]: getattr(a, 'foo') Out[81]: <bound method A.foo of <__main__.A object at 0x2970550>> rev check In [82]: getattr(a, 'foo')() in foo
14
30
'__setattr__' ,
Date Categories Tags Permalink Status
You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">
coder,1989@Shanghai;~~~~Love: 古典 Apple 阿森纳 美食 fan to 'A Song of Ice and Fire'~~~~标准上海话 标准普通话 能交流的英语 二把刀的德语~~~~主要工作是运维自动化和系统基础架构 contact E-Mail baniu.yao@gmail.com MSN frankymryao@hotmail.com 新浪微博 超大杯摩卡星冰乐 friend 亦草亦木的blog 大学好友的blog 美利坚coder 陪我歌唱 张美白的blog pwgc from Cici 鱼の贝壳
September 2013 S M T W T F S « Aug   Jan » 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30   Categories Culture Funny Life Linux Mac Movie NoSQL Ops Poem Programming Python RabbitMQ Reading Storm Uncategorized Zabbix Meta Log in Entries RSS Comments RSS WordPress.org
Cancel

No comments:

Post a Comment