随笔分类 - Python
摘要:```python import threading from threading import get_ident import time class Context: def __init__(self): object.__setattr__(self, '__global_context__
阅读全文
摘要:## 先写个 Flask demo ```python import time from flask import Flask app = Flask(__name__) @app.route('/') def hello(id): time.sleep(2) return 'Hello, Worl
阅读全文
摘要:观察者模式是一种行为设计模式,它允许你定义一种订阅机制,可以在对象事件发生时通知多个观察者对象。下面是一个简单的Python观察者模式代码示例: ```python class Subject: """ 被观察者类,维护观察者列表,并在状态发生改变时通知观察者 """ def __init__(se
阅读全文
摘要:Python中有多种实现单例模式的方式,以下是其中的几种: 1. 基础单例模式 ```python class Singleton(object): __instance = None def __new__(cls, *args, **kwargs): if not cls.__instance:
阅读全文
摘要:安装 marshmallow pip install marshmallow 基本使用 demo.py """ # python 序列化 - 序列化:对象转化为字典 - 反序列化: 字典转化为对象 """ from marshmallow import fields, post_load, Sche
阅读全文
摘要:SQLalchemy 基本使用 安装 SQLAlchemy pip install SQLalchemy 使用实例 结合这篇内容准备DB和数据 - MySQL 初步学习 model.py # coding: utf-8 from sqlalchemy import Column, DECIMAL,
阅读全文

浙公网安备 33010602011771号