首页 > 其他 > 详细

绑定方法与非绑定方法

时间:2019-12-25 20:43:55      阅读:64      评论:0      收藏:0      [点我收藏+]
# 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

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