当前位置:首页>python>Python yield 用法大全

Python yield 用法大全

  • 2026-01-31 19:18:46
Python yield 用法大全

yield 是 Python 中的关键字,用于定义生成器函数。与 return 不同,yield 会使函数返回一个生成器对象,这个对象可以迭代,但不会立即执行函数体。每次调用生成器的 next() 方法时,函数会从上次暂停的地方继续执行,直到遇到下一个 yield 语句。

1. 生成器 vs 普通函数

  • 普通函数:使用 return,一次性返回所有结果,函数执行结束
  • 生成器函数:使用 yield,可以多次返回值,每次返回后暂停,保持状态

2. 核心特性

  • 惰性求值:只在需要时生成值,节省内存
  • 状态保持:局部变量和执行状态在 yield 之间保持不变
  • 可迭代:生成器是迭代器,可以用在 for 循环中
  • 无限序列:可以表示无限长的序列(如无限流数据)

3. 用法

3.1 创建简单生成器

代码示例:

defbasic_generator():"""基本生成器示例"""    print("开始执行")yield1    print("继续执行")yield2    print("结束执行")yield3# 使用方式gen = basic_generator()print("第一次调用:", next(gen))  # 输出: 开始执行 → 1print("第二次调用:", next(gen))  # 输出: 继续执行 → 2print("第三次调用:", next(gen))  # 输出: 结束执行 → 3# 或者使用 for 循环for value in basic_generator():    print("循环获取:", value)

3.2 循环中使用 yield

代码示例:

deffibonacci_limited(n):"""生成前n个斐波那契数"""    a, b = 01    count = 0while count < n:yield a        a, b = b, a + b        count += 1# 使用fib = fibonacci_limited(10)print(list(fib))  # [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]# 或者直接迭代for num in fibonacci_limited(5):    print(num, end=' ')  # 0 1 1 2 3

3.3  yield from(Python 3.3+)

yield from 用于在生成器中委托给另一个生成器或可迭代对象,可以简化代码并提高效率。

  • 用于扁平化嵌套的生成器
  • 自动处理子生成器的异常
  • 可以接收子生成器的返回值

代码示例:

defchain_generators():"""连接多个生成器"""yieldfrom range(3)          # 委托给 rangeyieldfrom (x*2for x in range(3))  # 委托给生成器表达式yieldfrom ['a''b''c']   # 委托给列表print(list(chain_generators()))  # 输出: [0, 1, 2, 0, 2, 4, 'a', 'b', 'c']# 嵌套委托示例defflatten(nested_list):"""扁平化嵌套列表"""for sublist in nested_list:if isinstance(sublist, list):yieldfrom flatten(sublist)else:yield sublistnested = [1, [2, [34], 5], 6]print(list(flatten(nested)))  # [1, 2, 3, 4, 5, 6]

3.4 生成器表达式

生成器表达式是创建生成器的简洁语法,类似于列表推导式,但使用圆括号。

  • 语法:(expression for item in iterable if condition)
  • 惰性求值,不立即创建完整列表
  • 内存效率高

代码示例:

# 基本生成器表达式squares = (x**2for x in range(10))print(next(squares))  # 0print(next(squares))  # 1print(list(squares))  # [4, 9, 16, 25, 36, 49, 64, 81]# 带条件的生成器表达式even_squares = (x**2for x in range(10if x % 2 == 0)print(list(even_squares))  # [0, 4, 16, 36, 64]# 多层循环pairs = ((x, y) for x in range(3for y in range(3))print(list(pairs))  # [(0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0), (2,1), (2,2)]# 管道式处理numbers = range(100)pipeline = (    x * 2# 步骤1: 乘以2for x in numbers         # 输入if x % 3 == 0# 步骤2: 过滤3的倍数if x < 50# 步骤3: 只取小于50的)print(list(pipeline)[:5])  # [0, 6, 12, 18, 24]

3.5 协程(Coroutine)

生成器可以用于实现简单的协程,支持双向通信。

  • 使用 .send(value) 向生成器发送数据
  • 使用 .throw(exception) 向生成器抛出异常
  • 使用 .close() 关闭生成器
  • yield 可以接收外部发送的值

代码示例:

defcoroutine_example():"""简单的协程示例"""    print("协程启动")try:whileTrue:            received = yield# 接收外部发送的值            print(f"收到: {received}")except GeneratorExit:        print("协程关闭")except ValueError as e:        print(f"捕获异常: {e}")yield"处理了异常"# 可以继续yield# 使用协程coro = coroutine_example()next(coro)              # 启动协程,输出: "协程启动"coro.send("Hello")      # 输出: "收到: Hello"coro.send(123)          # 输出: "收到: 123"# 抛出异常coro.throw(ValueError("测试异常"))  # 输出: "捕获异常: 测试异常"print(next(coro))                   # 输出: "处理了异常"coro.close()            # 输出: "协程关闭"# 带初始值的协程defaccumulator():"""累加器协程"""    total = 0whileTrue:        value = yield totalif value isNone:break        total += valueacc = accumulator()next(acc)               # 启动print(acc.send(10))     # 输出: 10print(acc.send(20))     # 输出: 30print(acc.send(5))      # 输出: 35

3.6 生成器作为上下文管理器

生成器可以和 contextlib.contextmanager 装饰器结合,创建自定义上下文管理器。

  • 使用 @contextmanager 装饰器
  • yield 之前的部分相当于 __enter__
  • yield 之后的部分相当于 __exit__

代码示例:

from contextlib import contextmanager@contextmanagerdeftimer():"""计时上下文管理器"""import time    start = time.time()try:yield# 这里可以yield一个值给as变量finally:        end = time.time()        print(f"耗时: {end - start:.2f}秒")# 使用with timer():    sum(range(1000000))  # 输出: 耗时: 0.02秒# 带返回值的上下文管理器@contextmanagerdefopen_file(filename, mode='r'):"""文件操作的上下文管理器"""    file = open(filename, mode)try:yield file  # 将文件对象交给用户finally:        file.close()with open_file('test.txt''w'as f:    f.write("Hello, World!")

4、应用举例

4.1 处理大文件

代码示例:

defread_large_file(file_path, chunk_size=1024):"""分块读取大文件"""with open(file_path, 'r', encoding='utf-8'as f:whileTrue:            chunk = f.read(chunk_size)ifnot chunk:breakyield chunkdefprocess_log_file(file_path):"""逐行处理日志文件,过滤包含ERROR的行"""with open(file_path, 'r'as f:for line in f:if'ERROR'in line:yield line.strip()# 使用for error_line in process_log_file('app.log'):    print(f"发现错误: {error_line}")

4.2 无限序列

代码示例:

definfinite_counter(start=0):"""无限计数器"""whileTrue:yield start        start += 1definfinite_random():"""无限随机数生成器"""import randomwhileTrue:yield random.random()# 限制使用counter = infinite_counter(10)for _ in range(5):    print(next(counter), end=' ')  # 10 11 12 13 14# 使用itertools.islice限制from itertools import islicerandom_gen = infinite_random()first_5 = list(islice(random_gen, 5))print(first_5)

4.3 数据管道和流处理

代码示例:

defdata_pipeline(data):"""数据处理管道"""# 第一阶段:过滤    filtered = (item for item in data if item > 0)# 第二阶段:转换    transformed = (item * 2for item in filtered)# 第三阶段:分组yieldfrom transformed# 复杂管道示例defetl_pipeline(data_stream):"""ETL管道:提取、转换、加载"""# 提取:从原始数据流    raw_data = (item for item in data_stream)# 转换:清理和转换数据deftransform():for item in raw_data:# 清理数据            cleaned = str(item).strip().lower()if cleaned:  # 跳过空值yield cleaned# 加载:批处理    batch_size = 100    batch = []for item in transform():        batch.append(item)if len(batch) >= batch_size:yield batch            batch = []if batch:  # 处理最后一批yield batch# 模拟数据流test_data = ["  Hello  ""  WORLD  """"  Python  "None"  Generator  "]for batch in etl_pipeline(test_data):    print(f"处理批次: {batch}")

4.4 状态机实现

代码示例:

defstate_machine():"""简单的状态机"""    state = "START"whileTrue:if state == "START":            print("状态: START")            command = yieldif command == "go":                state = "RUNNING"elif state == "RUNNING":            print("状态: RUNNING")            command = yieldif command == "stop":                state = "STOPPED"elif command == "pause":                state = "PAUSED"elif state == "PAUSED":            print("状态: PAUSED")            command = yieldif command == "resume":                state = "RUNNING"elif command == "stop":                state = "STOPPED"elif state == "STOPPED":            print("状态: STOPPED")break# 使用状态机sm = state_machine()next(sm)                # 启动sm.send("go")           # 切换到RUNNINGsm.send("pause")        # 切换到PAUSEDsm.send("resume")       # 切回RUNNINGsm.send("stop")         # 切换到STOPPED

5. 性能优化

1. 内存对比

代码示例:

import sysimport timedeftest_memory_performance():"""测试内存和性能对比"""    n = 1000000# 方法1:使用列表(占用大量内存)    print("方法1: 使用列表")    start = time.time()    lst = [x**2for x in range(n)]    memory_list = sys.getsizeof(lst)    time_list = time.time() - start    print(f"  内存: {memory_list:,} 字节")    print(f"  时间: {time_list:.3f} 秒")# 方法2:使用生成器(内存高效)    print("\n方法2: 使用生成器")    start = time.time()    gen = (x**2for x in range(n))    memory_gen = sys.getsizeof(gen)# 消费生成器    sum_gen = sum(gen)    time_gen = time.time() - start    print(f"  内存: {memory_gen:,} 字节")    print(f"  时间: {time_gen:.3f} 秒")    print(f"  总和: {sum_gen:,}")    print(f"\n内存节省: {(memory_list - memory_gen) / memory_list * 100:.1f}%")test_memory_performance()

2. 惰性求值优化

代码示例:

deflazy_evaluation_demo():"""惰性求值优化示例"""# 过早求值(不推荐)defprocess_data_eager(data):# 这里立即创建了所有中间列表        filtered = [x for x in data if x > 0]  # 中间列表1        squared = [x**2for x in filtered]     # 中间列表2return sum(squared)                    # 最终结果# 惰性求值(推荐)defprocess_data_lazy(data):# 使用生成器表达式,没有中间列表        filtered = (x for x in data if x > 0)        squared = (x**2for x in filtered)return sum(squared)# 测试import random    data = [random.randint(-100100for _ in range(1000000)]import time    start = time.time()    result1 = process_data_eager(data)    time1 = time.time() - start    start = time.time()    result2 = process_data_lazy(data)    time2 = time.time() - start    print(f"过早求值: 结果={result1:,}, 时间={time1:.3f}秒")    print(f"惰性求值: 结果={result2:,}, 时间={time2:.3f}秒")    print(f"速度提升: {time1/time2:.1f}倍")lazy_evaluation_demo()

6. 注意事项

代码示例:

defcommon_mistakes():"""常见错误示例"""# 错误1:重复使用已耗尽的生成器    gen = (x for x in range(3))    print("错误1 - 重复使用生成器:")    print(f"  第一次: {list(gen)}")  # [0, 1, 2]    print(f"  第二次: {list(gen)}")  # [] - 空了!# 错误2:修改外部变量defbad_generator():        results = []for i in range(3):            results.append(i)yield results  # 每次都返回同一个列表的引用    print("\n错误2 - 返回可变对象引用:")    bg = bad_generator()for item in bg:        print(f"  {item}")  # 每次都是[0, 1, 2],而不是[0], [0,1], [0,1,2]# 正确做法:返回副本或不可变对象defgood_generator():        results = []for i in range(3):            results.append(i)yield results.copy()  # 返回副本    print("\n正确做法 - 返回副本:")    gg = good_generator()for item in gg:        print(f"  {item}")  # [0], [0,1], [0,1,2]common_mistakes()

7. 特殊用法

1. 递归生成器

代码示例:

defrecursive_generator(n):"""递归生成器"""if n <= 0:yield0else:yield nyieldfrom recursive_generator(n-1)print(list(recursive_generator(5)))  # [5, 4, 3, 2, 1, 0]# 遍历树结构classTreeNode:def__init__(self, value, left=None, right=None):        self.value = value        self.left = left        self.right = rightdefinorder_traversal(node):"""中序遍历二叉树"""if node:yieldfrom inorder_traversal(node.left)yield node.valueyieldfrom inorder_traversal(node.right)# 构建示例树tree = TreeNode(1,                TreeNode(2,                         TreeNode(4),                         TreeNode(5)),                TreeNode(3,                         TreeNode(6),                         TreeNode(7)))print(list(inorder_traversal(tree)))  # [4, 2, 5, 1, 6, 3, 7]

2. 异步生成器(Python 3.6+)

代码示例:

import asyncioasyncdefasync_generator():"""异步生成器"""for i in range(5):await asyncio.sleep(0.1)  # 模拟异步操作yield iasyncdefuse_async_generator():"""使用异步生成器"""asyncfor value in async_generator():        print(f"异步获取: {value}")# 运行asyncio.run(use_async_generator())

总结

yield 是 Python 中非常强大的特性,主要用途包括:

  1. 创建生成器:实现惰性求值,节省内存
  2. 实现协程:支持双向通信的轻量级并发
  3. 构建数据管道:处理流式数据
  4. 创建无限序列:表示潜在的无限数据流
  5. 实现状态机:保持状态的可迭代对象

掌握这些用法,有助于我们写出更高效、更 Pythonic 的代码。


作者简介:码上工坊,探索用编程为己赋能,定期分享编程知识和项目实战经验。持续学习、适应变化、记录点滴、复盘反思、成长进步。

重要提示:本文主要是记录自己的学习与实践过程,所提内容或者观点仅代表个人意见,只是我以为的,不代表完全正确,欢迎交流讨论。

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-02-07 13:31:10 HTTP/2.0 GET : https://f.mffb.com.cn/a/470294.html
  2. 运行时间 : 0.197108s [ 吞吐率:5.07req/s ] 内存消耗:4,944.12kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=718945933468a1176746fcf2e7989e72
  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.000555s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000774s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.002888s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.002494s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000533s ]
  6. SELECT * FROM `set` [ RunTime:0.003139s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000651s ]
  8. SELECT * FROM `article` WHERE `id` = 470294 LIMIT 1 [ RunTime:0.014679s ]
  9. UPDATE `article` SET `lasttime` = 1770442270 WHERE `id` = 470294 [ RunTime:0.003423s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000889s ]
  11. SELECT * FROM `article` WHERE `id` < 470294 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.001418s ]
  12. SELECT * FROM `article` WHERE `id` > 470294 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000430s ]
  13. SELECT * FROM `article` WHERE `id` < 470294 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.021443s ]
  14. SELECT * FROM `article` WHERE `id` < 470294 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.055429s ]
  15. SELECT * FROM `article` WHERE `id` < 470294 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.018062s ]
0.198782s