main.py 571 B

1234567891011121314151617181920212223
  1. import time
  2. #from mywifi import my_wifi
  3. from work_led import WorckLed
  4. class Device():
  5. _instance = None
  6. # 单例模式:WiFi实例化只能有一次,实例化多个 mywifi 对象将始终返回同一个-
  7. def __new__(cls, *args, **kwargs):
  8. if cls._instance is None:
  9. cls._instance = super().__new__(cls)
  10. return cls._instance # 返回的是内存地址
  11. def __init__(self) -> None:
  12. print("device init")
  13. self.wled= WorckLed(2)
  14. def main():
  15. wled= WorckLed(2)
  16. if __name__ == '__main__':
  17. main()