Python类操作

规范:注意函数命令规范。

import sys
class ZookeeperManager(): # class ClassName: 类命名规范
def __init__(self, zk_host, zk_port, zk_path, timeout=5):
self.zk_host = zk_host
self.zk_port = zk_port
self.zk_path = zk_path
self.timeout = timeout

def zk_conn(self): #class_suite 类体规范
try:
print('start zk_conn ...')
except Exception as e:
print("connect zk fail ... ") + str(e)
def MainInput():
try:
print('======MainInput=====')
zkt = ZookeeperManager('10.208.16.55','2181','kafka/elogomscore')
print(zkt.zk_host)
zkt.zk_conn()
except Exception as err:
print(err)
if __name__ == '__main__':
try:
MainInput()
finally:
sys.exit()
22

 

posted @ 2021-12-24 17:03  wang_wei123  阅读(50)  评论(0编辑  收藏  举报