python单例模式示例
程序员文章站
2022-03-07 16:04:49
...
# -*- coding: utf-8 -*-
class SendMessage(object):
"""调用第三方接口发送短信的功能"""
def __new__(cls, *args, **kwargs):
if not hasattr(cls, "_instance_"):
cls._instance_ = super(SendMessage, cls).__new__(cls)
cls.interface_url = "www.yangxiao1.com"
print "第一次进来"
return cls._instance_
def send_msg(self, sim, msg):
url = self.interface_url + "?msg=" + msg + "&phone=" + sim
print url
s = SendMessage()
s.send_msg("110", "hello,110")
s2 = SendMessage()
s2.send_msg("120", "hello,120")
s3 = SendMessage()
s3.send_msg("119", "hello,119")
上一篇: psr0和psr4区别
下一篇: 三种单例模式的写法