当前位置:首页>python>Python 零基础100天—Day24 魔术方法

Python 零基础100天—Day24 魔术方法

  • 2026-07-02 02:03:08
Python 零基础100天—Day24 魔术方法

🐍 魔术方法 — 让对象像内置类型一样优雅

🕐 预计用时:2-3 小时 | 🎯目标:掌握 __str__/__repr__/__len__/__eq__/__lt__、运算符重载


📖 今日目录

  1. 什么是魔术方法?
  2. 字符串表示:__str__ 与 __repr__
  3. 长度:__len__
  4. 比较运算:__eq__/__ne__/__lt__/__gt__/__le__/__ge__
  5. 算术运算:__add__/__sub__/__mul__/__truediv__
  6. 容器协议:__getitem__/__setitem__/__contains__
  7. 可调用:__call__
  8. 上下文管理:__enter__/__exit__
  9. 实战练习
  10. 今日小结

1. 什么是魔术方法?

魔术方法(Magic Methods)是 Python 中以双下划线开头和结尾的特殊方法——它们让自定义对象像内置类型一样工作。

# 魔术方法无处不在
print(len([1, 2, 3]))       # __len__
print(1 + 2)                # __add__
print([1, 2] == [1, 2])     # __eq__
print("hello" < "world")    # __lt__
print(str(42))              # __str__

# 你也可以让自己的类支持这些操作!
魔术方法
触发方式
作用
__str__str(obj)
 / print(obj)
用户友好的字符串
__repr__repr(obj)
 / 交互式显示
开发者友好的字符串
__len__len(obj)
返回长度
__eq__obj1 == obj2
相等比较
__add__obj1 + obj2
加法运算
__getitem__obj[key]
索引/键访问
__call__obj(args)
像函数一样调用

2. 字符串表示:__str__ 与 __repr__

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __str__(self):
        """给用户看的:友好、易读"""
        return f"({self.x}, {self.y})"

    def __repr__(self):
        """给开发者看的:精确、可重建"""
        return f"Point({self.x}, {self.y})"

p = Point(3, 4)

# print() 和 str() 调用 __str__
print(p)           # (3, 4)
print(str(p))      # (3, 4)

# 交互式环境和 repr() 调用 __repr__
print(repr(p))     # Point(3, 4)

# 在列表中显示的是 __repr__
points = [Point(1, 2), Point(3, 4)]
print(points)      # [Point(1, 2), Point(3, 4)]

# 没有 __str__ 时,回退到 __repr__
# 没有 __repr__ 时,显示 <__main__.Point object at 0x...>
对比
__str__
__repr__
调用者
print()
 / str()
repr()
 / 交互式 / 列表内
目标用户
终端用户
开发者
风格
友好、易读
精确、可重建
建议
一定要实现
最好也实现

💡 黄金法则:
__repr__ 返回的字符串应该能 eval() 重建对象(理想情况)。
__str__ 返回用户友好的显示。
如果只实现一个,优先实现 __repr__


3. 长度:__len__

class ShoppingCart:
    def __init__(self):
        self.items = []

    def add(self, name, price, quantity=1):
        self.items.append({"name": name, "price": price, "quantity": quantity})

    def __len__(self):
        """让 len() 支持自定义对象"""
        return sum(item["quantity"] for item in self.items)

    def __str__(self):
        return f"购物车: {len(self)} 件商品, ¥{self.total:.2f}"

    @property
    def total(self):
        return sum(item["price"] * item["quantity"] for item in self.items)

cart = ShoppingCart()
cart.add("苹果", 5.5, 3)
cart.add("牛奶", 12, 2)
cart.add("面包", 8, 1)

print(len(cart))   # 6(3+2+1 件)
print(cart)        # 购物车: 6 件商品, ¥47.50

# len() 支持的前提是实现了 __len__
# if cart:  ← 这也会用到 __len__(非零为 True)

4. 比较运算

实现比较魔术方法,让对象支持 ==、!=、<、>、<=、>= 运算。

from functools import total_ordering

@total_ordering  # 只需实现 __eq__ 和 __lt__,自动生成其他
class Student:
    def __init__(self, name, score):
        self.name = name
        self.score = score

    def __eq__(self, other):
        """== 等于"""
        if not isinstance(other, Student):
            return NotImplemented
        return self.score == other.score

    def __lt__(self, other):
        """< 小于"""
        if not isinstance(other, Student):
            return NotImplemented
        return self.score < other.score

    # @total_ordering 自动生成以下方法:
    # __ne__(!=)、__gt__(>)、__le__(<=)、__ge__(>=)

    def __repr__(self):
        return f"Student('{self.name}', {self.score})"

s1 = Student("张三", 85)
s2 = Student("李四", 92)
s3 = Student("王五", 85)

print(s1 == s3)   # True(分数相同)
print(s1 < s2)    # True(85 < 92)
print(s2 > s1)    # True(92 > 85)
print(s1 <= s3)   # True
print(s2 >= s1)   # True

# 排序直接可用!
students = [s1, s2, s3]
print(sorted(students))  # [Student('张三',85), Student('王五',85), Student('李四',92)]

💡 @total_ordering 装饰器:
只需实现 __eq__ 和 __lt__,自动生成 __ne____gt____le____ge__
省时省力,强烈推荐!


5. 算术运算

class Vector:
    """二维向量类"""
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, other):
        """+ 加法"""
        return Vector(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        """- 减法"""
        return Vector(self.x - other.x, self.y - other.y)

    def __mul__(self, scalar):
        """* 乘法(标量)"""
        return Vector(self.x * scalar, self.y * scalar)

    def __rmul__(self, scalar):
        """* 右乘(3 * v 也能用)"""
        return self.__mul__(scalar)

    def __neg__(self):
        """- 取负"""
        return Vector(-self.x, -self.y)

    def __abs__(self):
        """abs() 向量长度"""
        return (self.x ** 2 + self.y ** 2) ** 0.5

    def __repr__(self):
        return f"Vector({self.x}, {self.y})"

v1 = Vector(3, 4)
v2 = Vector(1, 2)

print(v1 + v2)     # Vector(4, 6)
print(v1 - v2)     # Vector(2, 2)
print(v1 * 3)      # Vector(9, 12)
print(3 * v1)      # Vector(9, 12)(__rmul__)
print(-v1)         # Vector(-3, -4)
print(abs(v1))     # 5.0(勾股定理)

📋 常用算术魔术方法

方法
运算
示例
__add__
+
a + b
__sub__
-
a - b
__mul__
*
a * b
__truediv__
/
a / b
__floordiv__
//
a // b
__mod__
%
a % b
__pow__
**
a ** b
__neg__
取负
-a
__abs__
绝对值
abs(a)

6. 容器协议

class Playlist:
    """播放列表:像列表一样使用"""
    def __init__(self, name):
        self.name = name
        self.songs = []

    def add(self, song):
        self.songs.append(song)

    def __getitem__(self, index):
        """支持索引访问:playlist[0]"""
        return self.songs[index]

    def __setitem__(self, index, value):
        """支持索引赋值:playlist[0] = '新歌'"""
        self.songs[index] = value

    def __len__(self):
        """支持 len()"""
        return len(self.songs)

    def __contains__(self, item):
        """支持 in 运算符"""
        return item in self.songs

    def __iter__(self):
        """支持 for 循环"""
        return iter(self.songs)

    def __str__(self):
        return f"🎵 {self.name}: {len(self)} 首歌"

playlist = Playlist("我的最爱")
playlist.add("晴天")
playlist.add("七里香")
playlist.add("稻香")

# 索引访问
print(playlist[0])        # 晴天
print(playlist[-1])       # 稻香

# 索引赋值
playlist[0] = "青花瓷"
print(playlist[0])        # 青花瓷

# in 运算符
print("七里香" in playlist)  # True
print("双截棍" in playlist)  # False

# for 循环
for song in playlist:
    print(f"  🎵 {song}")

# len()
print(len(playlist))      # 3

💡 容器协议四件套:
__getitem__ — 索引/键访问
__setitem__ — 索引/键赋值
__contains__ — in 运算符
__iter__ — for 循环遍历
实现这四个,你的对象就像列表/字典一样好用!


7. __call__:让对象像函数一样调用

class Multiplier:
    """可调用的乘法器"""
    def __init__(self, factor):
        self.factor = factor

    def __call__(self, x):
        return x * self.factor

double = Multiplier(2)
triple = Multiplier(3)

print(double(5))    # 10
print(triple(5))    # 15

# 检查对象是否可调用
print(callable(double))   # True
print(callable(triple))   # True

# 用途:函数工厂、缓存、装饰器
class Cache:
    """简易缓存"""
    def __init__(self):
        self.data = {}

    def __call__(self, func):
        def wrapper(*args):
            if args not in self.data:
                self.data[args] = func(*args)
            return self.data[args]
        return wrapper

cache = Cache()

@cache
def expensive_calc(n):
    print(f"  计算 {n}...")
    return n ** 2

print(expensive_calc(5))  # 计算 5... → 25
print(expensive_calc(5))  # 25(直接返回缓存,不计算)

8. 上下文管理:__enter__ / __exit__

class Timer:
    """计时器上下文管理器"""
    def __init__(self, label=""):
        self.label = label

    def __enter__(self):
        import time
        self.start = time.time()
        print(f"⏱️ 开始: {self.label}")
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        import time
        self.elapsed = time.time() - self.start
        print(f"⏱️ 结束: {self.label} ({self.elapsed:.4f}秒)")
        return False  # 不抑制异常

# 使用 with 语句
with Timer("排序测试"):
    data = sorted(range(100000, 0, -1))

with Timer("求和测试"):
    total = sum(range(1000000))

# 也可以用类的实例
class DBConnection:
    """模拟数据库连接"""
    def __init__(self, host):
        self.host = host

    def __enter__(self):
        print(f"🔗 连接数据库: {self.host}")
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        print(f"🔌 断开数据库: {self.host}")
        return False

    def query(self, sql):
        print(f"  📝 执行: {sql}")

with DBConnection("localhost") as db:
    db.query("SELECT * FROM users")
    db.query("INSERT INTO logs ...")
# 自动断开连接

9. 实战练习

🎯 练习 1:Matrix 矩阵类(完整运算符重载)

class Matrix:
    def __init__(self, data):
        self.data = [row[:] for row in data]
        self.rows = len(data)
        self.cols = len(data[0]) if data else 0

    def __repr__(self):
        return f"Matrix({self.data})"

    def __str__(self):
        max_len = max(len(str(x)) for row in self.data for x in row)
        lines = []
        for row in self.data:
            line = "  ".join(f"{x:>{max_len}}" for x in row)
            lines.append(f"| {line} |")
        return "\n".join(lines)

    def __eq__(self, other):
        return self.data == other.data

    def __getitem__(self, pos):
        row, col = pos
        return self.data[row][col]

    def __setitem__(self, pos, value):
        row, col = pos
        self.data[row][col] = value

    def __add__(self, other):
        if self.rows != other.rows or self.cols != other.cols:
            raise ValueError("矩阵尺寸不匹配")
        result = [
            [self.data[i][j] + other.data[i][j] for j in range(self.cols)]
            for i in range(self.rows)
        ]
        return Matrix(result)

    def __sub__(self, other):
        if self.rows != other.rows or self.cols != other.cols:
            raise ValueError("矩阵尺寸不匹配")
        result = [
            [self.data[i][j] - other.data[i][j] for j in range(self.cols)]
            for i in range(self.rows)
        ]
        return Matrix(result)

    def __mul__(self, other):
        if isinstance(other, (int, float)):
            # 标量乘法
            result = [[self.data[i][j] * other for j in range(self.cols)] for i in range(self.rows)]
            return Matrix(result)
        elif isinstance(other, Matrix):
            # 矩阵乘法
            if self.cols != other.rows:
                raise ValueError(f"无法相乘: {self.rows}x{self.cols} * {other.rows}x{other.cols}")
            result = [
                [sum(self.data[i][k] * other.data[k][j] for k in range(self.cols)) for j in range(other.cols)]
                for i in range(self.rows)
            ]
            return Matrix(result)
        return NotImplemented

    def __rmul__(self, scalar):
        return self.__mul__(scalar)

    def __neg__(self):
        return self * -1

    def __len__(self):
        return self.rows * self.cols

    @property
    def T(self):
        """转置"""
        return Matrix([[self.data[j][i] for j in range(self.rows)] for i in range(self.cols)])

# 测试
A = Matrix([[1, 2], [3, 4]])
B = Matrix([[5, 6], [7, 8]])

print("A =")
print(A)
print("\nB =")
print(B)

print("\nA + B =")
print(A + B)

print("\nA * B (矩阵乘法) =")
print(A * B)

print("\nA * 3 (标量乘法) =")
print(A * 3)

print("\nA.T (转置) =")
print(A.T)

print(f"\nA[1][0] = {A[1, 0]}")
print(f"len(A) = {len(A)}")

🎯 练习 2:Money 货币类

from functools import total_ordering

@total_ordering
class Money:
    """货币类:支持运算和比较"""
    EXCHANGE_RATES = {
        ("USD", "CNY"): 7.24,
        ("CNY", "USD"): 1 / 7.24,
        ("EUR", "CNY"): 7.89,
        ("CNY", "EUR"): 1 / 7.89,
        ("USD", "EUR"): 0.92,
        ("EUR", "USD"): 1 / 0.92,
    }

    def __init__(self, amount, currency="CNY"):
        self.amount = round(amount, 2)
        self.currency = currency

    def _convert(self, other):
        """统一货币后比较"""
        if self.currency == other.currency:
            return self.amount, other.amount
        key = (self.currency, other.currency)
        if key in self.EXCHANGE_RATES:
            return self.amount, round(other.amount * self.EXCHANGE_RATES[key], 2)
        raise ValueError(f"不支持的转换: {key}")

    def __eq__(self, other):
        if not isinstance(other, Money):
            return NotImplemented
        s, o = self._convert(other)
        return s == o

    def __lt__(self, other):
        if not isinstance(other, Money):
            return NotImplemented
        s, o = self._convert(other)
        return s < o

    def __add__(self, other):
        if not isinstance(other, Money):
            return NotImplemented
        if self.currency == other.currency:
            return Money(self.amount + other.amount, self.currency)
        key = (other.currency, self.currency)
        converted = round(other.amount * self.EXCHANGE_RATES.get(key, 0), 2)
        return Money(self.amount + converted, self.currency)

    def __sub__(self, other):
        if not isinstance(other, Money):
            return NotImplemented
        if self.currency == other.currency:
            return Money(self.amount - other.amount, self.currency)
        key = (other.currency, self.currency)
        converted = round(other.amount * self.EXCHANGE_RATES.get(key, 0), 2)
        return Money(self.amount - converted, self.currency)

    def __mul__(self, scalar):
        return Money(self.amount * scalar, self.currency)

    def __rmul__(self, scalar):
        return self.__mul__(scalar)

    def __neg__(self):
        return Money(-self.amount, self.currency)

    def __abs__(self):
        return Money(abs(self.amount), self.currency)

    def __repr__(self):
        return f"Money({self.amount}, '{self.currency}')"

    def __str__(self):
        symbols = {"CNY": "¥", "USD": "$", "EUR": "€"}
        symbol = symbols.get(self.currency, self.currency + " ")
        return f"{symbol}{self.amount:,.2f}"

# 测试
price1 = Money(100, "CNY")
price2 = Money(15, "USD")
price3 = Money(12, "EUR")

print(f"价格1: {price1}")       # ¥100.00
print(f"价格2: {price2}")       # $15.00
print(f"价格1 + 价格2: {price1 + price2}")  # ¥208.60
print(f"价格1 > 价格2: {price1 > price2}")   # True
print(f"3倍价格1: {3 * price1}")  # ¥300.00

# 排序
prices = [price1, price2, price3, Money(50, "CNY")]
for p in sorted(prices):
    print(f"  {p}")

10. 今日小结

分类
魔术方法
触发方式
字符串
__str__
 / __repr__
print()
 / repr()
长度
__len__len(obj)
比较
__eq__
 / __lt__ / __gt__...
==
 / < / >...
算术
__add__
 / __sub__ / __mul__...
+
 / - / *...
容器
__getitem__
 / __contains__ / __iter__
[]
 / in / for
可调用
__call__obj()
上下文
__enter__
 / __exit__
with obj

🧠 记忆口诀:
双下划线魔术法,对象秒变内置家。
str 给人看,repr 给码看。
len 算长度,eq 判相等。
add 加 sub 减,mul 乘 truediv 除。
getitem 像列表,call 像函数。
enter exit with 用,total_ordering 省代码。

🔮 预告: Day 25 综合练习 — 🎯 项目 1:学生管理系统(OOP 架构、文件存储、增删改查菜单)。把 Day21-Day24 学的全部用起来!

轻松时刻:

请在微信客户端打开

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-03 02:30:01 HTTP/2.0 GET : https://f.mffb.com.cn/a/497068.html
  2. 运行时间 : 0.147017s [ 吞吐率:6.80req/s ] 内存消耗:5,444.57kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=2a3027f73c36f7a96e50725c407c8971
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000540s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000831s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000325s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000270s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000501s ]
  6. SELECT * FROM `set` [ RunTime:0.000190s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000571s ]
  8. SELECT * FROM `article` WHERE `id` = 497068 LIMIT 1 [ RunTime:0.000497s ]
  9. UPDATE `article` SET `lasttime` = 1783017001 WHERE `id` = 497068 [ RunTime:0.006950s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000299s ]
  11. SELECT * FROM `article` WHERE `id` < 497068 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000484s ]
  12. SELECT * FROM `article` WHERE `id` > 497068 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000374s ]
  13. SELECT * FROM `article` WHERE `id` < 497068 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.007534s ]
  14. SELECT * FROM `article` WHERE `id` < 497068 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.014792s ]
  15. SELECT * FROM `article` WHERE `id` < 497068 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.039157s ]
0.148606s