当前位置:首页>python>Python 3 入门与进阶(十五):Pythonic编程——编码规范、性能优化与最佳实践

Python 3 入门与进阶(十五):Pythonic编程——编码规范、性能优化与最佳实践

  • 2026-02-09 23:56:34
Python 3 入门与进阶(十五):Pythonic编程——编码规范、性能优化与最佳实践

大家好,我是煜道。

今天我们一起来学习 Pythonic编程——编码规范、性能优化与最佳实践

引言

Pythonic并非一个正式的技术术语,而是指遵循Python设计哲学和惯用写法的编程风格。编写Pythonic代码意味着充分利用Python的特性,写出简洁、优雅、可读性强的程序。 Python之禅(The Zen of Python)告诉我们:"Simple is better than complex"(简洁胜于复杂),"Readability counts"(可读性很重要)。

本文将系统介绍Pythonic编程的核心原则,包括PEP 8编码规范、常用惯用写法、性能优化技巧以及常见误区的规避。通过本文的学习,我们将能够写出更加地道的Python代码,提升代码质量和开发效率。

01 PEP 8编码规范

1.1 代码布局

# 缩进:使用4个空格defmy_function():    print("Hello")# 行长度:限制在79字符以内long_line = "This is a very long line that should be broken into multiple lines for readability"# 空白行:函数间两个空行,类间一个空行classMyClass:passclassAnotherClass:passdeffunction():pass# 导入:每个导入单独一行import osimport sysfrom collections import defaultdict# 避免尾随空格line = "No trailing spaces"# 好的# line = "Trailing spaces "  # 不好的

1.2 命名规范

# 变量和函数:snake_caseuser_name = "Alice"defcalculate_total():pass# 常量:UPPER_SNAKE_CASEMAX_CONNECTIONS = 100DEFAULT_TIMEOUT = 30# 类:PascalCaseclassUserController:pass# 私有方法/变量:前导下划线classBankAccount:def__init__(self, balance):        self._balance = balancedef_calculate_interest(self):pass# 避免的名称冲突:后置下划线class_ = "class"list_ = [123]

1.3 表达式与语句

# 链式比较# 不好的写法if x > 0and x < 10:pass# 好的写法if0 < x < 10:pass# 多变量赋值# 不好的写法temp = xx = yy = temp# 好的写法x, y = y, x# 条件表达式# 好的写法status = "active"if user.is_active else"inactive"

02 Pythonic惯用写法

2.1 条件判断

# 检查空值# 不好的写法if len(my_list) > 0:pass# 好的写法if my_list:  # 空列表为Falsepass# 检查空字典if my_dict:  # 空字典为Falsepass# 默认值# 不好的写法name = ""if user.name:    name = user.name# 好的写法name = user.name or""# 或name = user.name if user.name else""# 字典访问# 不好的写法if key in my_dict:    value = my_dict[key]else:    value = None# 好的写法value = my_dict.get(key)  # 默认Nonevalue = my_dict.get(key, default_value)

2.2 循环惯用写法

# 遍历枚举# 不好的写法for i in range(len(my_list)):    print(i, my_list[i])# 好的写法for i, item in enumerate(my_list):    print(i, item)# 并行遍历# 不好的写法for i in range(min(len(list1), len(list2))):    print(list1[i], list2[i])# 好的写法for item1, item2 in zip(list1, list2):    print(item1, item2)# 反向遍历for item in reversed(my_list):    print(item)# 带索引的反向遍历for i, item in enumerate(reversed(my_list)):    print(i, item)

2.3 列表操作

# 列表推导式# 不好的写法squares = []for x in range(10):    squares.append(x ** 2)# 好的写法squares = [x ** 2for x in range(10)]# 条件过滤# 不好的写法evens = []for x in range(10):if x % 2 == 0:        evens.append(x)# 好的写法evens = [x for x in range(10if x % 2 == 0]# 字典推导式squares_dict = {x: x ** 2for x in range(5)}# {0: 0, 1: 1, 2: 4, 3: 9, 4: 16}# 集合推导式unique_squares = {x ** 2for x in range(-34)}# {0, 1, 4, 9}

2.4 打开文件

# 不好的写法f = open("file.txt""r")try:    content = f.read()finally:    f.close()# 好的写法(使用with语句)with open("file.txt""r"as f:    content = f.read()# 多文件with open("input.txt"as infile, open("output.txt""w"as outfile:    outfile.write(infile.read())

2.5 交换变量

# 交换两个变量a, b = b, a# 交换多个变量a, b, c = c, a, b

2.6 使用生成器

# 不好的写法:一次性读取大文件with open("large_file.txt"as f:    lines = f.readlines()# 好的写法:惰性读取with open("large_file.txt"as f:for line in f:        process(line)# 使用生成器表达式# 不好的写法total = sum([x for x in range(1000000if x % 2 == 0])# 好的写法total = sum(x for x in range(1000000if x % 2 == 0)

03 常见反模式与规避

3.1 避免过度使用类

# 不好的写法:简单功能过度封装classStringFormatter:    @staticmethoddefformat(s):return s.strip().lower()# 好的写法:使用函数defformat_string(s):return s.strip().lower()# 什么时候使用类# 1. 需要维护状态# 2. 需要多个方法# 3. 需要继承或多态classConfig:def__init__(self, values):        self._values = valuesdefget(self, key, default=None):return self._values.get(key, default)defset(self, key, value):        self._values[key] = value

3.2 避免魔法数字

# 不好的写法for i in range(7):if i == 3:  # 什么是3?pass# 好的写法DAYS_IN_WEEK = 7SPECIAL_DAY = 3for i in range(DAYS_IN_WEEK):if i == SPECIAL_DAY:pass

3.3 避免深层嵌套

# 不好的写法:深层嵌套defprocess(data):if data:if data.get('status'):if data['status'] == 'valid':if data.get('items'):for item in data['items']:if item.get('price') > 100:                            process_item(item)# 好的写法:提前返回/卫语句defprocess(data):ifnot data:returnifnot data.get('status'or data['status'] != 'valid':return    items = data.get('items', [])for item in items:if item.get('price'0) > 100:            process_item(item)

3.4 避免可变默认参数

# 不好的写法defadd_item(item, item_list=[]):    item_list.append(item)return item_list# 每次调用共享默认列表!add_item("a")  # ['a']add_item("b")  # ['a', 'b']# 好的写法defadd_item(item, item_list=None):if item_list isNone:        item_list = []    item_list.append(item)return item_list

3.5 正确比较

# 使用==比较值# 使用is比较身份# 不好的写法if value == None:  # 应该使用is Nonepassif value == True:  # 应该使用is True或直接if valuepass# 好的写法if value isNone:passif value isTrue:passif value:  # 真值判断pass

04 性能优化

4.1 字符串拼接

# 不好的写法:频繁拼接result = ""for i in range(1000):    result += str(i)# 好的写法1:使用joinparts = []for i in range(1000):    parts.append(str(i))result = "".join(parts)# 好的写法2:列表推导式result = "".join(str(i) for i in range(1000))

4.2 使用局部变量

# 不好的写法:频繁全局查找defprocess():for i in range(10000):        result = math.sqrt(i)  # math是全局变量return result# 好的写法:使用局部变量defprocess():    sqrt = math.sqrt  # 局部引用for i in range(10000):        result = sqrt(i)return result

4.3 使用slots

# 减少内存占用classPoint:    __slots__ = ('x''y')def__init__(self, x, y):        self.x = x        self.y = y# __slots__禁止__dict__,节省内存import sysp1 = Point(12)p2 = Point(34)print(sys.getsizeof(p1))  # 比普通类小

4.4 使用适当的数据结构

# 频繁查找使用set# 不好的写法defcheck_exists(items, target):for item in items:if item == target:returnTruereturnFalse# 好的写法defcheck_exists(items, target):    item_set = set(items)return target in item_set# 频繁尾部添加使用dequefrom collections import deque# 不好的写法my_list = []for i in range(10000):    my_list.append(i)# pop(0)是O(n)操作# 好的写法my_deque = deque()for i in range(10000):    my_deque.append(i)# popleft()是O(1)操作

4.5 使用生成器表达式

# 不好的写法:一次性生成列表total = sum([x ** 2for x in range(1000000)])# 好的写法:使用生成器表达式total = sum(x ** 2for x in range(1000000))

4.6 使用itertools

import itertools# 笛卡尔积for x, y in itertools.product(range(3), range(3)):    print(f"({x}{y})")# 组合for combo in itertools.combinations([1234], 2):    print(combo)  # (1, 2), (1, 3), ...# 排列for perm in itertools.permutations([123], 2):    print(perm)  # (1, 2), (1, 3), (2, 1), ...# 链式迭代for item in itertools.chain(list1, list2, list3):    print(item)

05 代码组织与重构

5.1 函数设计原则

# 单一职责# 不好的写法defprocess_user(user):    validate(user)           # 验证    save_to_database(user)   # 保存    send_notification(user)  # 通知# 好的写法defvalidate_user(user):passdefsave_user(user):passdefnotify_user(user):passdefprocess_user(user):    validate_user(user)    save_user(user)    notify_user(user)

5.2 使用上下文管理器

# 自定义上下文管理器classTimer:def__enter__(self):        self.start = time.time()return selfdef__exit__(self, exc_type, exc_val, exc_tb):        self.end = time.time()        print(f"Elapsed: {self.end - self.start:.4f}s")with Timer():# 代码块计时    time.sleep(1)

5.3 错误处理

# 使用特定异常# 不好的写法try:    process()except Exception:pass# 好的写法try:    process()except (ValueError, TypeError) as e:    print(f"Error: {e}")except KeyboardInterrupt:    print("User interrupted")except:raise# 重新抛出未知异常

5.4 使用with语句

# 自定义上下文管理器from contextlib import contextmanager@contextmanagerdeffile_lock(filename):# 获取锁    print(f"Locking {filename}")try:yieldfinally:        print(f"Unlocking {filename}")with file_lock("data.txt"):    print("Processing file")

06 测试与文档

6.1 单元测试

import unittestclassTestStringMethods(unittest.TestCase):deftest_upper(self):        self.assertEqual('foo'.upper(), 'FOO')deftest_isupper(self):        self.assertTrue('FOO'.isupper())        self.assertFalse('Foo'.isupper())deftest_split(self):        s = 'hello world'        self.assertEqual(s.split(), ['hello''world'])if __name__ == '__main__':    unittest.main()

6.2 类型注解

# Python 3.5+ 类型注解from typing import List, Dict, Optional, Uniondefgreet(name: str, age: int) -> str:returnf"Hello, {name}! You are {age} years old."defprocess_items(items: List[int]) -> int:return sum(items)defget_value(data: Dict[str, int], key: str) -> Optional[int]:return data.get(key)# Python 3.12+ 泛型语法defprocess_items[T](items: list[T]) -> list[T]:return items

6.3 文档字符串

defcalculate_area(radius: float) -> float:"""Calculate the area of a circle.    Args:        radius: The radius of the circle.    Returns:        The area of the circle.    Raises:        ValueError: If radius is negative.    """if radius < 0:raise ValueError("Radius cannot be negative")import mathreturn math.pi * radius ** 2

07 调试与profiling

7.1 调试技巧

# 使用pdb调试import pdbdefbuggy_function(x):    pdb.set_trace()  # 设置断点return x * 2# 使用日志调试import logginglogging.basicConfig(level=logging.INFO)logger = logging.getLogger(__name__)defprocess(data):    logger.debug(f"Processing: {data}")    result = data * 2    logger.info(f"Result: {result}")return result

7.2 性能分析

import cProfileimport pstatsdefprofile_function():# 分析函数    cProfile.run("main()""profile_stats")    p = pstats.Stats("profile_stats")    p.sort_stats('cumulative').print_stats(10)

08 小结

本文系统介绍了Pythonic编程的各个方面:

  1. 编码规范:PEP 8标准、命名规范、代码布局。
  2. 惯用写法:条件判断、循环、列表推导式的Pythonic写法。
  3. 反模式规避:过度封装、魔法数字、深层嵌套。
  4. 性能优化:字符串拼接、数据结构选择、生成器。
  5. 代码组织:单一职责、上下文管理器、错误处理。
  6. 测试与文档:单元测试、类型注解、文档字符串。

编写Pythonic代码是一个持续学习的过程。遵循Python的设计哲学,写出简洁、可读、高效的代码,是每个Python开发者的追求。

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-02-10 03:11:12 HTTP/2.0 GET : https://f.mffb.com.cn/a/474668.html
  2. 运行时间 : 0.564694s [ 吞吐率:1.77req/s ] 内存消耗:4,837.38kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=ec667c5a2dfd1452f74b612555868d04
  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.000396s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000819s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.001992s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000366s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000715s ]
  6. SELECT * FROM `set` [ RunTime:0.000259s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000728s ]
  8. SELECT * FROM `article` WHERE `id` = 474668 LIMIT 1 [ RunTime:0.026297s ]
  9. UPDATE `article` SET `lasttime` = 1770664272 WHERE `id` = 474668 [ RunTime:0.027738s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.004007s ]
  11. SELECT * FROM `article` WHERE `id` < 474668 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.009997s ]
  12. SELECT * FROM `article` WHERE `id` > 474668 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.003762s ]
  13. SELECT * FROM `article` WHERE `id` < 474668 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.308893s ]
  14. SELECT * FROM `article` WHERE `id` < 474668 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.096304s ]
  15. SELECT * FROM `article` WHERE `id` < 474668 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.012865s ]
0.566327s