staticmethod
class Mysql:
def __init__(self,ip,port):
self.ip = ip
self.port = port
@staticmethod
def create_id():
import uuid
return uuid.uuid4()
obj = Mysql('127.0.0.1','3306')
## 像普通函数一样调用就可以,不会自动传参,需要人工传参
print(Mysql.create_id()) ## 57c42038-b169-4f25-9057-d83795d097cc
print(obj.create_id()) ## 485372bc-efca-4da8-a446-b11c7bbf3c9b
No Comments