绑定方法与非绑定方法

# import settings
# class MySQL:
# def __init__(self,host,port):
# self.host=host
# self.port=port
#
# @classmethod
# def from_conf(cls):
# return cls(settings.HOST,settings.PORT)
# conn=MySQL('127.1.1.1',9527)
# conn=MySQL(settings.HOST,settings.PORT)
'''
绑定方法:绑定给谁就由谁来调用,谁来调用就会把谁当作第一个参数自动传入
'''
# conn=MySQL.from_conf()
# print(conn.host,conn.port)
'''
127.1.1.1 9527
'''
# import time,settings,hashlib
# class MySQL:
# def __init__(self,host,port):
# self.host=host
# self.port=port
#
# def func(self):
# print('%s 说:阿那他'%self.name)
#
# @classmethod
# def from_conf(cls):
# return cls(settings.HOST,settings.PORT)
#
# def create_id():
# m=hashlib.md5()
# m.update(str(time.process_time()).encode('utf-8'))
# return m.hexdigest()

# conn=MySQL.from_conf()
# print(MySQL.create_id())
'''
time.clock在Python 3.3中已被弃用,将从Python 3.8中删除:改用time.perf_counter或time.process_time代替time.clock
'''
'''
fa00eca46f5e08b1721f3d30af281e6c
'''
# import time,settings,hashlib
# class MySQL:
# def __init__(self,host,port):
# self.host=host
# self.port=port
#
# def func(self):
# print('%s 说:阿那他'%self.name)
#
# @classmethod
# def from_conf(cls):
# return cls(settings.HOST,settings.PORT)
#
# @staticmethod
# def create_id():
# m=hashlib.md5()
# m.update(str(time.process_time()).encode('utf-8'))
# return m.hexdigest()
#
# conn=MySQL.from_conf()
# print(MySQL.create_id)
# print(conn.create_id)
'''
<function MySQL.create_id at 0x00000131324635E8>
<function MySQL.create_id at 0x00000131324635E8>
'''
# print(MySQL.create_id())
# print(conn.create_id())
'''
2428a4883e5dc1b29352d505666ccadf
2428a4883e5dc1b29352d505666ccadf
'''
# import time,settings,hashlib
# class MySQL:
# def __init__(self,host,port):
# self.host=host
# self.port=port
#
# def func(self):
# print('%s 说:阿那他'%self.name)
#
# @classmethod
# def from_conf(cls):
# return cls(settings.HOST,settings.PORT)
#
# @staticmethod
# def create_id(n):
# m=hashlib.md5()
# m.update(str(time.process_time()+n).encode('utf-8'))
# return m.hexdigest()
#
# conn=MySQL.from_conf()
# print(MySQL.create_id(1))
# print(conn.create_id(2))
'''
3a5d90e70cf774b42477bfca08f4b457
44017e4195a5beb916e81ed57d1b6f61
'''
原文地址:https://www.cnblogs.com/0B0S/p/12098446.html