#_*_ encoding: utf-8 _*_ @author: ty hery 2019/8/28
class MySQL:
def __init__(self,ip,port,id):
self.id=id
self.ip=ip
self.port=port
def tell_info(self):
print("<ip:%s port:%s id:%s>"%(self.ip,self.port,self.id))
@classmethod
def form_conf(cls):
return cls(‘192.168.141.2‘,4396,26)
@staticmethod
def creat_id():
import uuid
return uuid.uuid4()
#方法一
obj1=MySQL(‘10.01.11‘,3360,56)
obj1.tell_info()
# 方法二
obj2=MySQL.form_conf()
print(obj2,type(obj2))
obj2.tell_info()
输出:<ip:10.01.11 port:3360 id:56>
<__main__.MySQL object at 0x0000000009FE6518> <class ‘__main__.MySQL‘>
<ip:192.168.141.2 port:4396 id:26>
mysql的类方法导入配置