当前位置:首页>python>Python学习--KeyError 详解

Python学习--KeyError 详解

  • 2026-04-13 17:45:11
Python学习--KeyError 详解

一、什么是 KeyError?

KeyError 是 Python 中当你尝试访问字典(dict)中不存在的键时抛出的异常。这是字典操作中最常见的错误之一,表示你试图获取的键在字典中不存在。

二、KeyError 的常见场景

1. 访问不存在的键

# 字典定义person = {    'name''Alice',    'age'25,    'city''Beijing'}print(f"字典内容: {person}")print(f"存在的键: {list(person.keys())}")# 访问存在的键print(person['name'])  # Aliceprint(person['age'])   # 25# 访问不存在的键try:    print(person['email'])except KeyError as e:    print(f"错误: 键 {e} 不存在")

2. 动态键名错误

# 变量作为键名user_input = 'phone'user_data = {    'name''张三',    'age'30}try:    print(user_data[user_input])except KeyError as e:    print(f"键 '{user_input}' 不存在,可用键: {list(user_data.keys())}")

3. 嵌套字典访问

# 嵌套字典config = {    'database': {        'host''localhost',        'port'3306    },    'cache': {        'type''redis'    }}# 访问存在的嵌套键print(config['database']['host'])  # localhost# 访问不存在的嵌套键try:    print(config['database']['password'])except KeyError as e:    print(f"嵌套键错误: {e}")# 访问不存在的顶级键try:    print(config['logging']['level'])except KeyError as e:    print(f"顶级键错误: {e}")

三、KeyError 的触发场景

1. 字典推导式错误

def dict_comprehension_error():    """字典推导式中的键错误"""    # 从现有字典创建新字典    original = {'a'1'b'2'c'3}    # 错误:访问不存在的键    try:        new_dict = {k: original[k.upper()] for k in original}    except KeyError as e:        print(f"推导式错误: 键 {e} 不存在")    # 正确方式    new_dict = {k: v for k, v in original.items()}    print(f"正确方式: {new_dict}")dict_comprehension_error()

2. 默认值字典的误用

from collections import defaultdictdef defaultdict_misuse():    """defaultdict 的误用"""    # 创建默认值字典    dd = defaultdict(int)  # 默认值为 0    dd['a'] = 1    dd['b'] = 2    # 访问不存在的键会返回默认值,不会报错    print(dd['c'])  # 0(不会报错)    # 但普通字典会报错    normal_dict = {'a'1'b'2}    try:        print(normal_dict['c'])    except KeyError as e:        print(f"普通字典错误: {e}")    # 注意:defaultdict 会创建不存在的键    print(dd)  # defaultdict(<class 'int'>, {'a': 1, 'b': 2, 'c': 0})defaultdict_misuse()

3. JSON 数据处理

import jsondef json_processing_error():    """JSON 数据处理中的键错误"""    json_data = '''    {        "user": {            "name": "Alice",            "age": 25        }    }    '''    data = json.loads(json_data)    # 访问存在的键    print(data['user']['name'])  # Alice    # 访问不存在的键    try:        print(data['user']['email'])    except KeyError as e:        print(f"JSON 数据错误: 缺少键 {e}")    # 安全访问嵌套 JSON    def safe_json_get(data, keys, default=None):        """安全获取嵌套 JSON 数据"""        current = data        for key in keys:            if isinstance(current, dict):                current = current.get(key)                if current is None:                    return default            else:                return default        return current    print(safe_json_get(data, ['user''email'], 'unknown@example.com'))json_processing_error()

四、处理 KeyError 的方法

1. 使用 get() 方法

def use_get_method():    """使用 get() 方法安全访问"""    user = {        'name''Bob',        'age'30    }    # get() 方法:键不存在时返回 None    name = user.get('name')    email = user.get('email')    print(f"name: {name}")      # Bob    print(f"email: {email}")    # None    # 提供默认值    email = user.get('email''default@example.com')    phone = user.get('phone''unknown')    print(f"email: {email}")    # default@example.com    print(f"phone: {phone}")    # unknown    # 链式 get    config = {        'database': {            'host''localhost'        }    }    host = config.get('database', {}).get('host''127.0.0.1')    port = config.get('database', {}).get('port'3306)    print(f"host: {host}")  # localhost    print(f"port: {port}")  # 3306use_get_method()

2. 使用 setdefault() 方法

def use_setdefault():    """使用 setdefault() 设置默认值"""    data = {'a'1'b'2}    # setdefault: 如果键存在返回其值,否则设置并返回默认值    value1 = data.setdefault('a'100)    value2 = data.setdefault('c'300)    print(f"value1: {value1}")  # 1    print(f"value2: {value2}")  # 300    print(f"data: {data}")      # {'a': 1, 'b': 2, 'c': 300}    # 实际应用:统计词频    text = "hello world hello python world hello"    word_count = {}    for word in text.split():        word_count[word] = word_count.setdefault(word, 0) + 1    print(f"词频统计: {word_count}")use_setdefault()

3. 使用 defaultdict

from collections import defaultdictdef use_defaultdict():    """使用 defaultdict 自动处理缺失键"""    # 默认值为 0    dd = defaultdict(int)    dd['a'] += 1    dd['b'] += 2    dd['c'] += 3    print(f"defaultdict(int): {dict(dd)}")    # 默认值为列表    dd_list = defaultdict(list)    dd_list['fruits'].append('apple')    dd_list['fruits'].append('banana')    dd_list['vegetables'].append('carrot')    print(f"defaultdict(list): {dict(dd_list)}")    # 默认值为自定义函数    def default_value():        return {'count'0'total'0}    dd_custom = defaultdict(default_value)    dd_custom['product1']['count'] += 1    dd_custom['product1']['total'] += 100    dd_custom['product2']['count'] += 1    print(f"defaultdict(custom): {dict(dd_custom)}")use_defaultdict()

4. 使用 try-except 捕获

def use_try_except():    """使用异常处理捕获 KeyError"""    config = {        'host''localhost',        'port'8080    }    def get_config(key, default=None):        """安全获取配置"""        try:            return config[key]        except KeyError:            print(f"警告: 配置项 '{key}' 不存在,使用默认值 {default}")            return default    # 使用    host = get_config('host''127.0.0.1')    port = get_config('port'80)    timeout = get_config('timeout'30)    print(f"host: {host}")       # localhost    print(f"port: {port}")       # 8080    print(f"timeout: {timeout}"# 30use_try_except()

五、常见陷阱和解决方案

1. 可变默认值陷阱

def mutable_default_trap():    """可变默认值的陷阱"""    # 错误:使用可变对象作为默认值    def add_to_dict_bad(key, value, target={}):        target[key] = value        return target    d1 = add_to_dict_bad('a'1)    d2 = add_to_dict_bad('b'2)    print(f"d1: {d1}")  # {'a': 1, 'b': 2}    print(f"d2: {d2}")  # {'a': 1, 'b': 2}    print(f"d1 is d2: {d1 is d2}")  # True(共享同一个字典)    # 正确:使用 None 作为默认值    def add_to_dict_good(key, value, target=None):        if target is None:            target = {}        target[key] = value        return target    d3 = add_to_dict_good('a'1)    d4 = add_to_dict_good('b'2)    print(f"d3: {d3}")  # {'a': 1}    print(f"d4: {d4}")  # {'b': 2}    print(f"d3 is d4: {d3 is d4}")  # Falsemutable_default_trap()

2. 键类型错误

def key_type_trap():    """键类型错误的陷阱"""    # 字典的键可以是不同类型    data = {        1'integer key',        '1''string key',        (1,): 'tuple key'    }    # 访问时类型必须匹配    print(data[1])      # integer key    print(data['1'])    # string key    # 错误:类型不匹配    try:        print(data['1'])  # 正确        print(data['1.0'])  # 不存在    except KeyError as e:        print(f"类型错误: 键 {e} 不存在")    # 从用户输入获取的键可能是字符串    user_input = "1"    try:        print(data[user_input])  # 正确,因为键是字符串    except KeyError:        print("键不存在")key_type_trap()

3. 并发修改

import threadingimport timedef concurrent_modification_trap():    """并发修改字典的陷阱"""    shared_dict = {'a'1'b'2'c'3}    def modify_dict():        for i in range(100):            shared_dict[f'key_{i}'] = i            time.sleep(0.001)    def read_dict():        for _ in range(100):            try:                # 可能在迭代过程中字典被修改                for key in list(shared_dict.keys()):                    value = shared_dict[key]  # 可能引发 KeyError            except KeyError as e:                print(f"并发错误: {e}")    t1 = threading.Thread(target=modify_dict)    t2 = threading.Thread(target=read_dict)    t1.start()    t2.start()    t1.join()    t2.join()# concurrent_modification_trap()# 解决方案:使用锁class ThreadSafeDict:    """线程安全的字典"""    def __init__(self):        self._dict = {}        self._lock = threading.RLock()    def get(self, key, default=None):        with self._lock:            return self._dict.get(key, default)    def set(self, key, value):        with self._lock:            self._dict[key] = value    def delete(self, key):        with self._lock:            try:                del self._dict[key]                return True            except KeyError:                return False    def keys(self):        with self._lock:            return list(self._dict.keys())    def items(self):        with self._lock:            return list(self._dict.items())

六、避免 KeyError 的最佳实践

1. 使用字典的 get 方法

def best_practice_get():    """使用 get 方法的最佳实践"""    user = {'name''Alice''age'25}    # 不好的做法    try:        email = user['email']    except KeyError:        email = 'default@example.com'    # 好的做法    email = user.get('email''default@example.com')    # 链式获取    config = {        'database': {            'host''localhost'        }    }    # 不好的做法    try:        host = config['database']['host']    except KeyError:        host = '127.0.0.1'    # 好的做法    host = config.get('database', {}).get('host''127.0.0.1')best_practice_get()

2. 使用 defaultdict 进行分组

def best_practice_defaultdict():    """使用 defaultdict 的最佳实践"""    # 不好的做法    data = [('a'1), ('b'2), ('a'3), ('b'4), ('c'5)]    grouped_bad = {}    for key, value in data:        if key not in grouped_bad:            grouped_bad[key] = []        grouped_bad[key].append(value)    # 好的做法    from collections import defaultdict    grouped_good = defaultdict(list)    for key, value in data:        grouped_good[key].append(value)    print(f"分组结果: {dict(grouped_good)}")best_practice_defaultdict()

3. 使用 setdefault 简化代码

def best_practice_setdefault():    """使用 setdefault 的最佳实践"""    # 不好的做法    word_count = {}    words = ['apple''banana''apple''orange''banana''apple']    for word in words:        if word in word_count:            word_count[word] += 1        else:            word_count[word] = 1    # 好的做法    word_count = {}    for word in words:        word_count[word] = word_count.setdefault(word, 0) + 1    print(f"词频统计: {word_count}")best_practice_setdefault()

4. 使用 collections.ChainMap

from collections import ChainMapdef best_practice_chainmap():    """使用 ChainMap 合并多个字典"""    defaults = {        'host''localhost',        'port'8080,        'debug'False,        'timeout'30    }    user_config = {        'host''production.example.com',        'debug'True    }    # 合并配置,user_config 优先级更高    config = ChainMap(user_config, defaults)    # 访问配置    print(f"host: {config['host']}")        # production.example.com    print(f"port: {config['port']}")        # 8080    print(f"debug: {config['debug']}")      # True    print(f"timeout: {config['timeout']}")  # 30    # 修改会影响第一个字典    config['timeout'] = 60    print(f"user_config: {user_config}")  # {'host': 'production.example.com', 'debug': True, 'timeout': 60}best_practice_chainmap()

七、总结

KeyError 要点表格

 特性
说明
 触发条件
访问字典中不存在的键
 常见原因
键名拼写错误、数据类型不匹配、动态键名错误
 处理方法get()
setdefault()defaultdicttry-except
 最佳实践
使用 get() 提供默认值,使用 defaultdict 自动初始化
 性能考虑get()
 比 try-except 略快,defaultdict 最高效

快速检查清单

 问题
检查项
 键名拼写正确吗?
检查大小写、下划线、拼写
 键的类型匹配吗?
字符串 vs 整数 vs 元组
 字典是否为空?
空字典无法访问任何键
 嵌套字典存在吗?
检查每一级字典是否存在
 并发访问安全吗?
多线程访问需要加锁

KeyError 是字典操作中最常见的异常之一。通过使用 get()setdefault()defaultdict 等工具,可以有效地避免和处理这类错误。理解字典的工作原理和正确使用这些方法,可以编写出更健壮、更易读的代码。

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-04-15 01:38:40 HTTP/2.0 GET : https://f.mffb.com.cn/a/486271.html
  2. 运行时间 : 0.115552s [ 吞吐率:8.65req/s ] 内存消耗:4,601.00kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=78ec7b184d3436786d4329a0e837494d
  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.000458s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000674s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000267s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000308s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000493s ]
  6. SELECT * FROM `set` [ RunTime:0.000194s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000501s ]
  8. SELECT * FROM `article` WHERE `id` = 486271 LIMIT 1 [ RunTime:0.000419s ]
  9. UPDATE `article` SET `lasttime` = 1776188320 WHERE `id` = 486271 [ RunTime:0.008231s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000234s ]
  11. SELECT * FROM `article` WHERE `id` < 486271 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000469s ]
  12. SELECT * FROM `article` WHERE `id` > 486271 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000377s ]
  13. SELECT * FROM `article` WHERE `id` < 486271 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.003159s ]
  14. SELECT * FROM `article` WHERE `id` < 486271 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.000680s ]
  15. SELECT * FROM `article` WHERE `id` < 486271 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.007759s ]
0.117130s