当前位置:首页>python>Python itertools 模块完全指南:让你的代码更优雅、更高效

Python itertools 模块完全指南:让你的代码更优雅、更高效

  • 2026-03-26 21:10:54
Python itertools 模块完全指南:让你的代码更优雅、更高效

掌握 itertools,告别繁琐的循环,写出 Pythonic 的代码。

引言

在 Python 编程中,我们经常需要处理迭代操作——遍历、组合、筛选、分组……如果这些操作都用 for 循环硬写,代码不仅冗长,而且效率低下。

itertools 模块正是为了解决这些问题而生。它提供了一系列快速、高效的迭代器工具,让你的代码更简洁、更 Pythonic。

本文将全面介绍 itertools 的核心功能,配合实例代码,帮助你彻底掌握这个强大的工具库。


一、无限迭代器

无限迭代器是 itertools 的特色功能,它们可以无限生成数据,直到你主动停止。

1. count() - 计数器

从指定数字开始,无限递增。

from itertools import count

# 从 10 开始,每次增加 2
for i in count(102):
    if i > 20:
        break
    print(i)
# 输出: 10, 12, 14, 16, 18, 20

2. cycle() - 循环迭代

无限循环遍历一个可迭代对象。

from itertools import cycle

colors = ['红''绿''蓝']
color_cycle = cycle(colors)

# 取前 7 个
for _ in range(7):
    print(next(color_cycle))
# 输出: 红, 绿, 蓝, 红, 绿, 蓝, 红

实际应用:实现轮询负载均衡。

servers = ['server1''server2''server3']
server_pool = cycle(servers)

# 每次请求选择下一个服务器
for request in range(10):
    server = next(server_pool)
    print(f"请求 {request+1} -> {server}")

3. repeat() - 重复元素

重复返回同一个元素,可指定次数。

from itertools import repeat

# 重复 '嗨' 5 次
for _ in repeat('嗨'5):
    print(_)
# 输出: 嗨, 嗨, 嗨, 嗨, 嗨

# 无限重复(不指定次数)
counter = 0
for _ in repeat('永远'):
    if counter >= 3:
        break
    print(_)
    counter += 1

二、有限迭代器

这类迭代器接受一个或多个可迭代对象,返回处理后的结果,直到输入耗尽。

1. accumulate() - 累积计算

对可迭代对象进行累积操作,默认是求和。

from itertools import accumulate

numbers = [12345]

# 默认累加
result = list(accumulate(numbers))
print(result)
# 输出: [1, 3, 6, 10, 15]  (1, 1+2, 1+2+3...)

# 自定义操作:累乘
import operator
result = list(accumulate(numbers, operator.mul))
print(result)
# 输出: [1, 2, 6, 24, 120]  (阶乘)

# 计算最大值累积
prices = [1009510298105103]
max_prices = list(accumulate(prices, max))
print(max_prices)
# 输出: [100, 100, 102, 102, 105, 105]

2. chain() - 连接多个可迭代对象

将多个可迭代对象串联成一个。

from itertools import chain

list1 = [123]
list2 = ['a''b''c']
list3 = [TrueFalse]

# 连接多个列表
result = list(chain(list1, list2, list3))
print(result)
# 输出: [1, 2, 3, 'a', 'b', 'c', True, False]

# 对比普通方法
# result = list1 + list2 + list3  # 效率低,创建新列表

# chain.from_iterable - 用于展平嵌套列表
nested = [[12], [34], [56]]
flat = list(chain.from_iterable(nested))
print(flat)
# 输出: [1, 2, 3, 4, 5, 6]

3. compress() - 按条件筛选

根据选择器对数据列表进行过滤。

from itertools import compress

data = ['A''B''C''D''E']
selectors = [TrueFalseTrueFalseTrue]

# 只保留对应 True 的元素
result = list(compress(data, selectors))
print(result)
# 输出: ['A', 'C', 'E']

# 实际应用:选择特定列
columns = ['姓名''年龄''城市''薪资']
use_column = [TrueTrueFalseTrue]  # 不需要城市
active_columns = list(compress(columns, use_column))
print(active_columns)
# 输出: ['姓名', '年龄', '薪资']

4. dropwhile() 和 takewhile()

根据条件截取序列。

from itertools import dropwhile, takewhile

numbers = [13574682]

# dropwhile: 只要条件为真就丢弃,一旦为假则保留剩余所有
dropped = list(dropwhile(lambda x: x < 5, numbers))
print(dropped)
# 输出: [5, 7, 4, 6, 8, 2]  (1,3被丢弃,5不小于5停止)

# takewhile: 只要条件为真就保留,一旦为假停止
taken = list(takewhile(lambda x: x < 5, numbers))
print(taken)
# 输出: [1, 3]  (遇到5停止)

# 实际应用:跳过文件头部注释
lines = [
    '# 这是注释',
    '# 作者:张三',
    '',
    'import os',
    'print("Hello")'
]
# 跳过空行和注释
code = list(dropwhile(lambda line: not line or line.startswith('#'), lines))
print(code)

5. filterfalse()

filter() 的反操作,保留使条件为假的元素。

from itertools import filterfalse

numbers = [12345678910]

# 筛选偶数(保留使条件为假的:x%2==1为奇数,取反)
evens = list(filterfalse(lambda x: x % 2, numbers))
print(evens)
# 输出: [2, 4, 6, 8, 10]

# 对比 filter
odds = list(filter(lambda x: x % 2, numbers))
print(odds)
# 输出: [1, 3, 5, 7, 9]

# 实际应用:过滤掉空值
data = ['hello''''world'None'python''''']
filtered = list(filterfalse(lambda x: not x, data))
print(filtered)
# 输出: ['hello', 'world', 'python']

6. groupby()

对可迭代对象进行分组(需要先排序)。

from itertools import groupby

# 注意:groupby 要求数据先按分组键排序!
data = [
    ('A''Alice'),
    ('A''Anna'),
    ('B''Bob'),
    ('B''Ben'),
    ('C''Carol')
]

# 按第一个字母分组
for key, group in groupby(data, key=lambda x: x[0]):
    print(f"字母 {key}{list(group)}")

# 输出:
# 字母 A: [('A', 'Alice'), ('A', 'Anna')]
# 字母 B: [('B', 'Bob'), ('B', 'Ben')]
# 字母 C: [('C', 'Carol')]

# 实际应用:统计连续相同的元素
from operator import itemgetter

events = [
    ('2024-01-01''login'),
    ('2024-01-02''login'),
    ('2024-01-03''logout'),
    ('2024-01-04''login'),
]

# 按事件类型分组(需要先排序)
events.sort(key=itemgetter(1))
for event_type, group in groupby(events, key=itemgetter(1)):
    count = len(list(group))
    print(f"{event_type}{count} 次")

7. islice() - 切片迭代器

对迭代器进行切片,支持负数索引(会消耗迭代器)。

from itertools import islice

numbers = iter(range(100))

# 取前 5 个
first_five = list(islice(numbers, 5))
print(first_five)
# 输出: [0, 1, 2, 3, 4]

# 取 10-14(从第10个开始,取5个)
middle = list(islice(numbers, 510))
print(middle)
# 输出: [5, 6, 7, 8, 9]

# 每 2 个取一个(步长为2)
every_second = list(islice(numbers, 0102))
print(every_second)
# 输出: [10, 12, 14, 16, 18]

# 对比普通切片(只能用于有索引的对象)
numbers_list = list(range(100))
print(numbers_list[5:10])  # 适用于列表

# islice 可以用于任何迭代器(文件、生成器等)

8. starmap()

将参数列表解包后传递给函数(类似 * 解包)。

from itertools import starmap

# 普通 map
args = [(23), (45), (67)]

# 使用 lambda 手动解包
result1 = list(map(lambda x: x[0] ** x[1], args))
print(result1)
# 输出: [8, 1024, 279936]

# 使用 starmap 自动解包
result2 = list(starmap(lambda x, y: x ** y, args))
print(result2)
# 输出: [8, 1024, 279936]

# 实际应用:批量计算距离
import math

coordinates = [
    ((00), (34)),    # 距离 5
    ((11), (45)),    # 距离 5
    ((00), (11)),    # 距离 √2
]

def distance(p1, p2):
    return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)

distances = list(starmap(distance, coordinates))
print(distances)
# 输出: [5.0, 5.0, 1.414...]

9. tee()

将一个迭代器分裂成多个独立的迭代器。

from itertools import tee

numbers = iter([12345])

# 分裂成 3 个独立迭代器
iter1, iter2, iter3 = tee(numbers, 3)

print(list(iter1))  # [1, 2, 3, 4, 5]
print(list(iter2))  # [1, 2, 3, 4, 5]
print(list(iter3))  # [1, 2, 3, 4, 5]

# 原迭代器已耗尽,不能再用
# print(list(numbers))  # 空列表

# 实际应用:同时计算总和与平均值
def sum_and_avg(iterable):
    it1, it2 = tee(iterable, 2)
    total = sum(it1)
    count = sum(1 for _ in it2)
    return total, total / count if count > 0 else 0

numbers = range(1101)  # 1-100
total, avg = sum_and_avg(numbers)
print(f"总和: {total}, 平均值: {avg}")
# 输出: 总和: 5050, 平均值: 50.5

10. zip_longest()

zip() 的增强版,可以处理长度不等的序列,用指定值填充。

from itertools import zip_longest

names = ['Alice''Bob''Carol']
ages = [2530]
cities = ['NYC''LA''Chicago''Houston']

# 普通 zip 以最短的为准
print(list(zip(names, ages, cities)))
# 输出: [('Alice', 25, 'NYC'), ('Bob', 30, 'LA')]

# zip_longest 以最长的为准,空缺填充 None
print(list(zip_longest(names, ages, cities)))
# 输出: 
# [('Alice', 25, 'NYC'), ('Bob', 30, 'LA'), ('Carol', None, 'Chicago'), (None, None, 'Houston')]

# 自定义填充值
print(list(zip_longest(names, ages, cities, fillvalue='未知')))
# 输出:
# [('Alice', 25, 'NYC'), ('Bob', 30, 'LA'), ('Carol', '未知', 'Chicago'), ('未知', '未知', 'Houston')]

三、组合迭代器

组合迭代器用于生成各种排列组合,在算法、概率统计等领域非常有用。

1. product() - 笛卡尔积

计算多个可迭代对象的笛卡尔积(所有可能的组合)。

from itertools import product

# 两个列表的笛卡尔积
colors = ['红''绿']
sizes = ['大''小']

result = list(product(colors, sizes))
print(result)
# 输出: [('红', '大'), ('红', '小'), ('绿', '大'), ('绿', '小')]

# 三个列表
materials = ['棉''麻']
result = list(product(colors, sizes, materials))
print(f"共有 {len(result)} 种组合")
# 输出: 共有 8 种组合

# 同一个列表的笛卡尔积(允许重复)
dice_faces = [123456]
# 掷两次骰子的所有可能
rolls = list(product(dice_faces, repeat=2))
print(f"掷两次骰子共有 {len(rolls)} 种可能")
# 输出: 掷两次骰子共有 36 种可能

# 计算点数和为 7 的概率
sum_to_7 = [roll for roll in rolls if sum(roll) == 7]
print(f"点数和为 7 的情况有 {len(sum_to_7)} 种,概率为 {len(sum_to_7)/len(rolls):.2%}")
# 输出: 点数和为 7 的情况有 6 种,概率为 16.67%

2. permutations() - 排列

生成所有可能的排列(考虑顺序)。

from itertools import permutations

items = ['A''B''C']

# 全排列
result = list(permutations(items))
print(f"3 个元素的全排列共 {len(result)} 种:")
for p in result:
    print(p)
# 输出:
# 3 个元素的全排列共 6 种:
# ('A', 'B', 'C')
# ('A', 'C', 'B')
# ('B', 'A', 'C')
# ('B', 'C', 'A')
# ('C', 'A', 'B')
# ('C', 'B', 'A')

# 部分排列(取 2 个)
result = list(permutations(items, 2))
print(f"\n从 3 个中取 2 个的排列共 {len(result)} 种:")
for p in result:
    print(p)
# 输出: 6 种 (A,B), (A,C), (B,A), (B,C), (C,A), (C,B)

# 实际应用:密码组合分析
digits = '123'
# 3 位数字密码的所有可能(数字不重复)
passwords = [''.join(p) for p in permutations(digits, 3)]
print(f"\n可能的 3 位密码(不重复): {passwords}")
# 输出: ['123', '132', '213', '231', '312', '321']

3. combinations() - 组合

生成所有可能的组合(不考虑顺序)。

from itertools import combinations

team = ['Alice''Bob''Carol''David']

# 选 2 人的所有组合
pairs = list(combinations(team, 2))
print(f"从 4 人中选 2 人,共 {len(pairs)} 种组合:")
for p in pairs:
    print(f"  {p[0]} & {p[1]}")
# 输出: 6 种组合

# 选 3 人的组合
trios = list(combinations(team, 3))
print(f"\n从 4 人中选 3 人,共 {len(trios)} 种组合")
# 输出: 4 种组合

# 实际应用:抽奖组合
import random
participants = ['张三''李四''王五''赵六''孙七']
# 抽取 3 人组成中奖小组
winning_groups = list(combinations(participants, 3))
print(f"\n共有 {len(winning_groups)} 种可能的 3 人组合")
# 随机选一组
lucky_group = random.choice(winning_groups)
print(f"中奖组合: {lucky_group}")

4. combinations_with_replacement() - 可重复组合

元素可以重复出现的组合。

from itertools import combinations_with_replacement

# 从 ['A', 'B'] 中选 2 个,允许重复
result = list(combinations_with_replacement(['A''B'], 2))
print(result)
# 输出: [('A', 'A'), ('A', 'B'), ('B', 'B')]
# 注意:普通 combinations 不会包含 ('A', 'A')

# 实际应用:购买组合
# 有 3 种水果,每种买 0-2 个,总共买 2 个
fruits = ['苹果''香蕉''橙子']
purchase_options = list(combinations_with_replacement(fruits, 2))
print(f"\n买 2 个水果的组合(可重复)共 {len(purchase_options)} 种:")
for opt in purchase_options:
    print(f"  {opt[0]} + {opt[1]}")
# 输出: 6 种组合(包括两个相同水果的情况)

四、实用技巧与最佳实践

1. 内存效率:迭代器 vs 列表

itertools 返回的都是迭代器,具有惰性求值特性,可以处理海量数据而不会耗尽内存。

from itertools import count, islice

# 高效:不存储所有数据
# 生成 0-999999,取前 10 个,不占用内存
first_10 = islice(count(), 10)
print(list(first_10))

# 低效:创建巨大列表
# numbers = list(range(1000000))  # 占用大量内存

2. 链式操作

多个 itertools 函数可以链式组合,实现复杂的数据处理。

from itertools import chain, islice, cycle

# 示例:生成无限循环的序列,取特定窗口
data = [123]
window = islice(cycle(data), 28)  # 跳过2个,取6个
print(list(window))
# 输出: [3, 1, 2, 3, 1, 2]

3. 与生成器表达式结合

itertools 与生成器表达式配合,可以编写简洁高效的代码。

from itertools import takewhile

# 生成斐波那契数列
# 使用 itertools 简化斐波那契生成
def fibonacci():
    a, b = 01
    while True:
        yield a
        a, b = b, a + b

# 获取小于 1000 的所有斐波那契数
fib_under_1000 = takewhile(lambda x: x < 1000, fibonacci())
print(list(fib_under_1000))
# 输出: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]

4. 常见场景速查表

场景 推荐函数 示例
无限计数 count() count(10, 2) → 10, 12, 14...
循环轮询 cycle() cycle(['A', 'B', 'C'])
累加/累乘 accumulate() accumulate([1,2,3]) → 1, 3, 6
扁平化 chain() chain(list1, list2)
展平嵌套 chain.from_iterable() chain.from_iterable(matrix)
分组 groupby() groupby(data, key=func)
笛卡尔积 product() product(A, B)
排列 permutations() permutations(items, 2)
组合 combinations() combinations(items, 2)

五、总结

itertools 是 Python 标准库中最强大、最高效的模块之一。掌握它可以让你:

  1. 写出更简洁的代码 - 用一行替代多行循环
  2. 提高运行效率 - 惰性求值节省内存
  3. 处理大规模数据 - 无需一次性加载所有数据
  4. 实现复杂算法 - 排列组合、笛卡尔积等

学习建议

  • 从常用函数开始:先掌握 chain()groupby()islice()
  • 结合实际场景:在工作中寻找可以用 itertools 优化的循环
  • 阅读源码:itertools 是用 C 实现的,了解实现原理有助于深入理解

掌握 itertools,让你的 Python 代码更加优雅、高效、Pythonic!

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-03-27 13:02:52 HTTP/2.0 GET : https://f.mffb.com.cn/a/481039.html
  2. 运行时间 : 0.109895s [ 吞吐率:9.10req/s ] 内存消耗:5,224.43kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=da00dc94f220ccf48eb4d2284a16c999
  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.000466s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000648s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000269s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000293s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000571s ]
  6. SELECT * FROM `set` [ RunTime:0.000240s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000749s ]
  8. SELECT * FROM `article` WHERE `id` = 481039 LIMIT 1 [ RunTime:0.001122s ]
  9. UPDATE `article` SET `lasttime` = 1774587772 WHERE `id` = 481039 [ RunTime:0.005774s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000267s ]
  11. SELECT * FROM `article` WHERE `id` < 481039 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000569s ]
  12. SELECT * FROM `article` WHERE `id` > 481039 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000402s ]
  13. SELECT * FROM `article` WHERE `id` < 481039 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.001554s ]
  14. SELECT * FROM `article` WHERE `id` < 481039 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.001995s ]
  15. SELECT * FROM `article` WHERE `id` < 481039 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.008048s ]
0.113712s