当前位置:首页>python>学Python半年后,我总结了5个后悔没早知道的事

学Python半年后,我总结了5个后悔没早知道的事

  • 2026-06-30 09:13:58
学Python半年后,我总结了5个后悔没早知道的事

送给正在学的你


前几个月参加聚会,有个朋友问我:“哥,你会爬虫吗
能不能帮我爬点数据

我问他:“你会什么

他愣了一下:“我...我学完了基础语法,课程看了三遍

我接着问:“那你能用Python做什么

他答不上来了

那天晚上他微信问我:“为什么我学了大半年感觉什么都没学会

我告诉他:“因为你一直在'假学习'

这不是个例
我花了半年时间,踩了无数坑,才明白一个道理——**学Python最大的坑,不是你不努力,而是你的学习方法从一开始就错了
**

今天把这份“后悔清单”分享给你,尤其是第5条,能让你少走至少三个月的弯路


你是不是也这样?

先别急着划走,看看下面这些场景你有没有中枪:

**你是不是每天刷教程视频,收藏了一堆,但从来不动手敲代码
**

“这个讲得真好,收藏

**你是不是学完基础语法就卡住了,想做项目但不知道从哪下手
**

“循环我会,函数我会,但让我写个程序——不会

**你是不是遇到问题就百度,复制粘贴代码,改个参数能用,但完全不懂原理
**

“为什么报错
不知道
复制粘贴试试另一个

**你是不是学了就忘,忘了又学,永远在零基础
**

“两周不碰代码,忘了60%

**你是不是觉得自己学了但派不上用场
想用来提升工作效率但不知道能干嘛
**

“Python除了打印hello world还能干啥

如果你中了两条以上——这篇文章就是写给你的


认知反转:问题不在努力,而在方法

99%的人学Python的路径是这样的:找一门课→刷完→收藏→结束

这就是问题所在

**你不是在学习,你是在消费知识
**

刷视频是消费,收藏是消费,甚至记笔记也是消费——消费嘛,谁不会
但消费完,你什么都没留下

真正有效的学习只需要三个字:用Python

不是“学Python”,是“用Python”

当你用Python解决了一个真实问题,学会的东西想忘都忘不掉

下面我给你5个真实场景,每个场景都有完整可运行的代码
你不需要全部弄懂,但至少选一个,立刻动手跑起来

这才是真正的学习捷径


技术详解:5个立刻能用的场景

场景1:自动整理乱糟糟的文件夹

每次下载东西桌面就乱成一团
不同类型的文件混在一起

来,自动给你整理

import os
import shutil
from pathlib import Path

deforganize_downloads(folder_path):
"""
    自动将文件夹中的文件按类型整理到对应子文件夹
    """

# 定义文件类型映射
    file_types = {
'images': ['.jpg''.jpeg''.png''.gif''.bmp''.webp'],
'文档': ['.pdf''.doc''.docx''.txt''.xls''.xlsx''.ppt''.pptx'],
'压缩包': ['.zip''.rar''.7z''.tar''.gz'],
'视频': ['.mp4''.avi''.mov''.mkv''.flv'],
'音频': ['.mp3''.wav''.aac''.flac'],
'代码': ['.py''.js''.html''.css''.java''.c''.cpp']
    }

# 创建一个Path对象,方便操作
    target_folder = Path(folder_path)

# 如果目标文件夹不存在,直接退出
ifnot target_folder.exists():
print(f"文件夹 {folder_path} 不存在")
return

# 遍历文件夹中的所有文件
for file in target_folder.iterdir():
# 跳过子文件夹
if file.is_dir():
continue

# 获取文件后缀并转为小写
        suffix = file.suffix.lower()

# 查找对应的类型分类
        found_category = None
for category, extensions in file_types.items():
if suffix in extensions:
                found_category = category
break

# 未分类的文件归入"其他"
ifnot found_category:
            found_category = '其他'

# 创建分类文件夹(如果不存在)
        category_folder = target_folder / found_category
        category_folder.mkdir(exist_ok=True)

# 移动文件
try:
            shutil.move(str(file), str(category_folder / file.name))
print(f"移动: {file.name} → {found_category}")
except Exception as e:
print(f"移动 {file.name} 失败: {e}")

# ===== 使用示例 =====
# 假设你想整理Downloads文件夹
downloads_path = os.path.expanduser("~/Downloads")
organize_downloads(downloads_path)

逐行解释:

1import os            # 导入操作系统模块,处理路径
2import shutil        # 导入高级文件操作模块,移动/复制文件
3from pathlib import Path  # 导入路径对象,更优雅地处理文件路径

第1-3行导入了需要的工具模块

5deforganize_downloads(folder_path):  # 定义整理函数,参数是要整理的文件夹路径

第5行定义函数,这样你可以重复使用

9      file_types = {    # 字典:文件后缀 → 分类名称
10'images': ['.jpg''.png', ...],
11'文档': ['.pdf''.doc', ...],
12          ...
13      }

第9-15行定义文件类型映射表,你可以根据需要修改
比如想加一个“表格”分类,就往里加

18      target_folder = Path(folder_path)  # 将字符串转为Path对象
20ifnot target_folder.exists():   # 检查文件夹是否存在
21print("不存在")
22return# 不存在就退出函数

第18-22行获取目标文件夹并做安全性检查

25for file in target_folder.iterdir():  # 遍历文件夹中每个文件
26if file.is_dir():                    # 跳过子文件夹,只处理文件
27continue

第25-27行遍历所有文件项,跳过文件夹

29          suffix = file.suffix.lower()  # 获取文件后缀,转小写统一处理
30          found_category = None# 先假设没找到分类
31for category, extensions in file_types.items():  # 遍历分类字典
32if suffix in extensions:    # 如果后缀在这个分类里
33                  found_category = category  # 记录找到的分类
34break# 找到了就跳出循环

第29-34行根据文件后缀找对应的分类

36ifnot found_category:            # 如果没找到任何分类
37          found_category = '其他'# 归入"其他"

第36-37行没找到分类的文件放入“其他”

39      category_folder = target_folder / found_category  # 拼接目标路径
40      category_folder.mkdir(exist_ok=True)               # 创建分类文件夹

第39-40行创建对应的子文件夹

43try:                           # 尝试移动文件
44          shutil.move(str(file), str(category_folder / file.name))
45print(f"移动: {file.name} → {found_category}")
46except Exception as e:         # 移动出错就打印错误
47print(f"移动 {file.name} 失败: {e}")

第43-47行实际移动文件,并打印移动结果

运行效果示例:

移动: screenshot.png → images
移动: report.pdf → 文档
移动: data.zip → 压缩包
移动: meeting.mp4 → 视频
移动: song.mp3 → 音频
移动: analysis.py → 代码
...

适用场景: 桌面乱、D下载乱的人的救星
每天下载几十个文件的人,一个脚本从此告别手动整理


场景2:批量重命名照片

手机里一堆IMG_001、IMG_002...分不清什么时候拍的

批量重命名,按修改日期自动归档

import os
import datetime
from pathlib import Path

defbatch_rename_with_date(folder_path, prefix="photo"):
"""
    批量重命名图片文件,按修改日期排列
    格式: photo_2024-01-15_001.jpg
    """

    target_folder = Path(folder_path)

# 支持的图片格式
    image_extensions = {'.jpg''.jpeg''.png''.gif''.bmp''.webp'}

# 获取所有图片文件
    image_files = [
        f for f in target_folder.iterdir()
if f.is_file() and f.suffix.lower() in image_extensions
    ]

# 按修改时间排序
    image_files.sort(key=lambda f: f.stat().st_mtime)

# 遍历重命名
for index, file inenumerate(image_files, start=1):
# 获取文件的修改时间
        timestamp = file.stat().st_mtime
        date_obj = datetime.datetime.fromtimestamp(timestamp)
        date_str = date_obj.strftime('%Y-%m-%d')  # 格式化为日期

# 构建新文件名
        new_name = f"{prefix}_{date_str}_{index:03d}{file.suffix}"
        new_path = file.parent / new_name

# 重命名(如果新文件名不一样的话)
if new_name != file.name:
# 处理重名情况:如果是已有的文件名,加个数字后缀
            counter = 1
while new_path.exists():
                new_name = f"{prefix}_{date_str}_{index:03d}_{counter}{file.suffix}"
                new_path = file.parent / new_name
                counter += 1

            file.rename(new_path)
print(f"{file.name} → {new_name}")

print(f"\n完成! 共处理 {len(image_files)} 个文件")

# ===== 使用示例 =====
photos_folder = os.path.expanduser("~/Pictures/手机照片")
batch_rename_with_date(photos_folder, prefix="vacation")

逐行解释:

1import os
2import datetime            # 导入日期时间模块
3from pathlib import Path

第1-3行导入模块

5defbatch_rename_with_date(folder_path, prefix="photo"):
6"""批量重命名函数"""

第5行函数定义,prefix参数让你自定义文件名前缀

9      image_extensions = {'.jpg''.jpeg''.png', ...}  # 支持的图片格式

第9行定义支持哪些文件格式

11# 获取所有图片文件
12      image_files = [
13          f for f in target_folder.iterdir()
14if f.is_file() and f.suffix.lower() in image_extensions
15      ]

第12-15行用列表推导式筛选出所有图片文件

17# 按修改时间排序
18      image_files.sort(key=lambda f: f.stat().st_mtime)

第17-18行按文件修改时间排序,这样同一时间拍的照片会排在一起

21for index, file inenumerate(image_files, start=1):
22          timestamp = file.stat().st_mtime          # 获取修改时间戳
23          date_obj = datetime.datetime.fromtimestamp(timestamp)  # 转为日期对象
24          date_str = date_obj.strftime('%Y-%m-%d'# 格式化为字符串

第21-24行遍历文件,把修改时间转成日期字符串

27          new_name = f"{prefix}_{date_str}_{index:03d}{file.suffix}"
28          new_path = file.parent / new_name

第27-28行构建新文件名,保持原文件后缀

31# 处理重名情况:如果文件名已存在
32          counter = 1
33while new_path.exists():
34              new_name = f"..._{counter}{file.suffix}"
35              counter += 1

第31-35行处理重名情况——如果已存在同名文件自动加数字后缀

38          file.rename(new_path)                     # 执行重命名
39print(f"{file.name} → {new_name}")

第38-39行实际重命名文件

运行效果示例:

IMG_001.jpg → vacation_2024-01-15_001.jpg
IMG_002.jpg → vacation_2024-01-15_002.jpg
IMG_003.jpg → vacation_2024-01-16_003.jpg

完成! 共处理 127 个文件

适用场景: 手机照片乱糟糟、找不到想要的照片、想按时间排序的人


场景3:获取网页数据(简单爬虫)

想获取某个网页上的特定数据
比如考研分数线、天气数据、股价

来,学会这个,你就超过90%的Python学习者了

import requests
from pathlib import Path
import datetime

deffetch_page_title(url):
"""
    获取网页标题的简单示例
    """

try:
# 发送GET请求,设置超时
        response = requests.get(url, timeout=10)
        response.raise_for_status()  # 检查请求是否成功

# 获取网页标题(<title>标签里的内容)
        content = response.text
        title_start = content.find('<title>')
        title_end = content.find('</title>')

if title_start != -1and title_end != -1:
            title = content[title_start + 7:title_end]
return title.strip()
else:
return"未找到标题"

except requests.exceptions.RequestException as e:
returnf"请求失败: {e}"

defsave_stock_data(stock_code, days=7):
"""
    获取股票历史数据的简化版本
    注意:需要使用真实数据接口,这里用示例演示
    """

# 这是一个模拟数据接口(不要用这个获取真实数据)
# 真实场景可以用 baostock、akshare 等免费库

print(f"获取股票 {stock_code} 最近 {days} 天数据...")

# 这里演示保存逻辑
    data_folder = Path.home() / "stock_data"
    data_folder.mkdir(exist_ok=True)

    today = datetime.datetime.now().strftime('%Y-%m-%d')
    filename = f"{stock_code}_{today}.txt"

# 模拟数据内容
    mock_content = f"""股票代码: {stock_code}
获取日期: {today}
数据天数: {days}

2024-01-01, 100.00, 101.50, 99.50, 100.80, 1000000
2024-01-02, 100.80, 102.00, 100.50, 101.20, 1200000
2024-01-03, 101.20, 103.50, 101.00, 102.80, 1500000
"""


# 写入文件
    save_path = data_folder / filename
withopen(save_path, 'w', encoding='utf-8'as f:
        f.write(mock_content)

print(f"数据已保存到: {save_path}")
return save_path

# ===== 使用示例 =====

# 示例1:获取网页标题
url = "https://www.baidu.com"
title = fetch_page_title(url)
print(f"百度首页标题: {title}")

# 示例2:保存股票数据
save_stock_data("000001")

逐行解释:

import requests                    # 发送HTTP请求的库
from pathlib import Path           # 路径处理
import datetime                  # 日期时间

基础导入

deffetch_page_title(url):
"""获取网页标题"""
try:
# 发送GET请求,超时10秒
        response = requests.get(url, timeout=10)
        response.raise_for_status()  # HTTP错误检查

第6-9行发送请求并检查是否成功
如果返回404或500会抛出异常

11          content = response.text  # 获取网页源码
12          title_start = content.find('<title>')
13          title_end = content.find('</title>')

第11-13行在网页源码中查找title标签
这个方法很原始但能说明原理

16if title_start != -1and title_end != -1:
17              title = content[title_start + 7:title_end]  # 切片提取标题
18return title.strip()                        # 去掉空白返回

第16-18行提取并返回标题

22defsave_stock_data(stock_code, days=7):
23"""获取股票数据"""

第22行定义股票数据函数

26      data_folder = Path.home() / "stock_data"# 用户主目录下的stock_data文件夹
27      data_folder.mkdir(exist_ok=True)

第26-27行创建数据保存目录

30      today = datetime.datetime.now().strftime('%Y-%m-%d')  # 获取今天日期
31      filename = f"{stock_code}_{today}.txt"# 构建文件名

第30-31行获取今天的日期用于文件名

34# 模拟数据(实际用 baostock 或 akshare 库获取真实数据)
35      mock_content = f"""股票代码: {stock_code}
36          获取日期: {today}
37          数据天数: {days}
38          ...
39      """

第34-39行这里用模拟数据演示
真实场景推荐用 baostock(免费)获取真实股票数据

42withopen(save_path, 'w', encoding='utf-8'as f:
43          f.write(mock_content)        # 写入文件

第42-43行写入文件

运行效果示例:

百度首页标题: 百度一下,你就知道
获取股票 000001 最近 7 天数据...
数据已保存到: /Users/xxx/stock_data/000001_2024-01-15.txt

适用场景: 想学爬虫但不知道从哪开始的小白
学会这个,你就可以尝试获取任何公开网页数据了

进阶推荐后面学习 BeautifulSoup 解析网页,或用 Selenium 抓动态内容


场景4:自动生成日志报告

每天手动统计数据
每周手动写报告

Python可以帮你自动生成

import datetime
from pathlib import Path

defgenerate_daily_report(log_file_path, output_format="markdown"):
"""
    读取日志文件,生成每日报告
    支持 markdown 格式
    """

    log_file = Path(log_file_path)

# 检查文件是否存在
ifnot log_file.exists():
print(f"日志文件不存在: {log_file_path}")
returnNone

# 读取日志内容
withopen(log_file, 'r', encoding='utf-8'as f:
        lines = f.readlines()

# 统计各项数据
    total_lines = len(lines)
    error_count = 0
    warning_count = 0
    info_count = 0

for line in lines:
        line = line.upper()
if'ERROR'in line:
            error_count += 1
elif'WARNING'in line or'WARN'in line:
            warning_count += 1
elif'INFO'in line:
            info_count += 1

# 今天的日期
    today = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%s')

# 生成报告
if output_format == "markdown":
        report = f"""# 每日日志报告

**生成时间**: {today}

## 统计摘要

| 项目 | 数量 |
|------|------|
| 总日志条数 | {total_lines} |
| 错误 (ERROR) | {error_count} |
| 警告 (WARNING) | {warning_count} |
| 信息 (INFO) | {info_count} |

## 最近10条日志

"""

添加最近10条日志

for line in lines[-10:]:
report += line

report += "```\n\n---\n报告自动生成"

else:
report = f"日报 ({today})\n总日志: {total_lines}, 错误: {error_count}, 警告: {warning_count}"

return report

def auto_backup_and_report(source_folder, backup_folder):
"""
自动备份文件夹并生成报告
"""
source = Path(source_folder)
backup = Path(backup_folder)

创建备份文件夹

backup.mkdir(parents=True, exist_ok=True)

统计文件数量

files = list(source.rglob('*'))
file_count = sum(1 for f in files if f.is_file())
folder_count = sum(1 for f in files if f.is_dir())

生成备份报告

today = datetime.datetime.now().strftime('%Y-%m-%d')
report = f"""# 自动备份报告

备份日期: {today}
源文件夹: {source}
备份位置: {backup}

统计

  • • 总文件数: {file_count}
  • • 总文件夹数: {folder_count}

自动生成于 {datetime.datetime.now()}
"""

保存报告

report_file = backup / f"backup_report_{today}.md"
with open(report_file, 'w', encoding='utf-8') as f:
f.write(report)

print(f"备份完成! 报告已保存到: {report_file}")
return report_file

===== 使用示例 =====

示例1:生成日志报告

假设有一个 app.log 文件

report = generate_daily_report("~/logs/app.log")

print(report)

示例2:自动备份

auto_backup_and_report(
source_folder="/Documents/工作文件",
backup_folder="
/Backups/工作文件_自动备份"
)


**逐行解释:**

```python
4  def generate_daily_report(log_file_path, output_format="markdown"):
5      """读取日志文件,生成每日报告"""

第4行定义日志报告函数。

9withopen(log_file, 'r', encoding='utf-10'as f:
10          lines = f.readlines()

第9-10行读取日志文件所有行。

13      error_count = 0
14      warning_count = 0
15      info_count = 0
16for line in lines:
17          line = line.upper()          # 转为大写方便匹配
18if'ERROR'in line:
19              error_count += 1
20elif'WARNING'in line:
21              warning_count += 1
22elif'INFO'in line:
23              info_count += 1

第16-23行遍历日志,统计各类型数量。

26if output_format == "markdown":
27          report = f"""# 每日日志报告
28  
29  **生成时间**: {today}
30  
31  ## 统计摘要
32  
33  | 项目 | 数量 |
34  |------|------|
35  | 总日志条数 | {total_lines} |
36  | 错误 | {error_count} |
...

第26-37行生成Markdown格式报告。

47defauto_backup_and_report(source_folder, backup_folder):
48"""自动备份文件夹"""

第47行定义自动备份函数。

52      files = list(source.rglob('*'))         # 递归获取所有文件
53      file_count = sum(1for f in files if f.is_file())  # 文件数
54      folder_count = sum(1for f in files if f.is_dir())  # 文件夹数

第52-54行统计文件数量,rglob('*')递归获取所有内容。

58      report = f"""# 自动备份报告
59  
60  **备份日期**: {today}
61  **源文件夹**: {source}
...

第58-64行生成备份报告。

67      report_file = backup / f"backup_report_{today}.md"
68withopen(report_file, 'w', encoding='utf-8'as f:
69          f.write(report)

第67-69行保存报告到文件。

运行效果示例:

# 自动备份报告

**备份日期**: 2024-01-15
**源文件夹**: /Users/xxx/Documents/工作文件
**备份位置**: /Users/xxx/Backups/工作文件_自动备份

## 统计

- 总文件数: 127
- 总文件夹数: 15


---

*自动生成于 2024-01-15 10:30:00*

适用场景: 运维人员、每天需要统计数据的人、想自动化工作流的人。


场景5:定时任务(真正解放双手)

上面的脚本都很好,但你想每天自动执行?

来,定时任务了解一下。

import time
import datetime
from pathlib import Path
import os

classAutoTaskScheduler:
"""
    简单的定时任务调度器
    每天在指定时间执行指定函数
    """


def__init__(self):
self.tasks = []  # 任务列表

defadd_daily_task(self, task_name, task_func, hour=9, minute=0):
"""
        添加每日任务
        参数:
            task_name: 任务名字
            task_func: 要执行的函数
            hour: 执行小时 (0-23)
            minute: 执行分钟 (0-59)
        """

        task = {
'name': task_name,
'func': task_func,
'hour': hour,
'minute': minute,
'last_run'None# 上次执行时间
        }
self.tasks.append(task)
print(f"已添加任务: {task_name}, 每天 {hour:02d}:{minute:02d} 执行")

defshould_run_now(self, task):
"""检查任务是否应该现在执行"""
        now = datetime.datetime.now()

# 检查是否到了执行时间
if now.hour == task['hour'and now.minute == task['minute']:
# 检查是否今天已经执行过
if task['last_run'isNone:
returnTrue

            last_run_time = datetime.datetime.strptime(
                task['last_run'], '%Y-%m-%d %H:%M:%S'
            )

# 如果上次执行是今天,就不再执行
if last_run_time.date() == now.date():
returnFalse

returnTrue

returnFalse

defrun(self, check_interval=60):
"""
        启动调度器
        check_interval: 检查间隔(秒)
        """

print(f"\n调度器启动! 每 {check_interval} 秒检查一次任务")
print("按 Ctrl+C 停止\n")

try:
whileTrue:
                now = datetime.datetime.now()

# 检查每个任务
for task inself.tasks:
ifself.should_run_now(task):
print(f"\n[{now}] 执行任务: {task['name']}")
try:
                            task['func']()
                            task['last_run'] = now.strftime('%Y-%m-%d %H:%M:%S')
print(f"[{now}] 任务完成!")
except Exception as e:
print(f"[{now}] 任务执行失败: {e}")

                time.sleep(check_interval)

except KeyboardInterrupt:
print("\n\n调度器已停止")

# ===== 任务示例函数 =====

defdaily_cleanup():
"""每日清理任务示例"""
    downloads = Path.home() / "Downloads"
print(f"检查并清理Downloads文件夹...")

    cleaned_count = 0
for file in downloads.iterdir():
if file.is_file():
# 清理30天前的文件
            age_days = (datetime.datetime.now() - datetime.datetime.fromtimestamp(
                file.stat().st_mtime
            )).days

if age_days > 30:
print(f"删除: {file.name} (文件年龄: {age_days}天)")
# file.unlink()  # 实际使用时取消注释
                cleaned_count += 1

print(f"清理完成,共删除 {cleaned_count} 个文件")

defdaily_report():
"""每日报告任务"""
print("生成每日报告...")
# 这里可以调用前面写的 generate_daily_report 函数
print("报告已生成并发送!")

# ===== 使用示例 =====

# 创建调度器
scheduler = AutoTaskScheduler()

# 添加每日任务
# 每天早上9点执行清理
scheduler.add_daily_task(
    task_name="每日清理",
    task_func=daily_cleanup,
    hour=9,
    minute=0
)

# 每天早上9点05分执行报告
scheduler.add_daily_task(
    task_name="每日报告",
    task_func=daily_report,
    hour=9,
    minute=5
)

# 启动!(测试时可以设置 check_interval=5 快速测试)
# scheduler.run(check_interval=60)

逐行解释:

9classAutoTaskScheduler:
10"""定时任务调度器类"""

第9行定义调度器类。

12def__init__(self):
13self.tasks = []  # 用列表存储所有任务

第12-13行初始化任务列表。

15defadd_daily_task(self, task_name, task_func, hour=9, minute=0):
16"""添加每日任务"""

第15行添加任务的方法。

17          task = {
18'name': task_name,      # 任务名
19'func': task_func,      # 要执行的函数
20'hour': hour,           # 执行时间:时
21'minute': minute,       # 执行时间:分
22'last_run'None# 上次执行时间
23          }
24self.tasks.append(task)

第17-24行构建任务字典并加入列表。

27defshould_run_now(self, task):
28"""检查是否应该现在执行"""
29          now = datetime.datetime.now()
30if now.hour == task['hour'and now.minute == task['minute']:
31# 检查是否今天已经执行过
...

第27-34行判断是否到了执行时间。

43defrun(self, check_interval=60):
44"""启动调度器,check_interval是检查间隔"""
45try:
46whileTrue:             # 无限循环
47# 检查每个任务
48for task inself.tasks:
49ifself.should_run_task(task):
50print(f"执行: {task['name']}")
51                          task['func']()  # 执行任务函数
52                          task['last_run'] = ...
53                  time.sleep(check_interval)  # 等待
...

第43-56行主循环:不断检查时间,到点就执行任务。

59defdaily_cleanup():
60"""每日清理示例:删除30天前的文件"""
61      downloads = Path.home() / "Downloads"
...

第59行开始是两个示例任务函数。

73for file in downloads.iterdir():
74if file.is_file():
75              age_days = ...  # 计算文件年龄
76if age_days > 30:  # 超过30天
77print(f"删除: {file.name}")
78# file.unlink()  # 实际删除前先注释测试

第73-78行遍历文件,计算年龄,删除超期的。

84# 创建调度器实例
85  scheduler = AutoTaskScheduler()
86
87# 添加任务:每天9点执行清理
88  scheduler.add_daily_task("每日清理", daily_cleanup, hour=9, minute=0)
89
90# 添加任务:每天9点05分执行报告
91  scheduler.add_daily_task("每日报告", daily_report, hour=9, minute=5)
92
93# 启动
94  scheduler.run()

第84-94行使用调度器的示例。

运行效果:

已添加任务: 每日清理, 每天 09:00 执行
已添加任务: 每日报告, 每天 09:05 执行

调度器启动! 每 60 秒检查一次任务
按 Ctrl+C 停止

[2024-01-15 09:00:00] 执行任务: 每日清理
检查并清理Downloads文件夹...
删除: old_file1.zip (文件年龄: 45天)
删除: temp_file.txt (文件年龄: 32天)
清理完成,共删除 2 个文件
[2024-01-15 09:00:00] 任务完成!

适用场景: 想真正自动化日常任务的人。

进阶建议

  • • 真实环境中,建议用系统的 crontab(Linux/Mac)或 Task Scheduler(Windows)
  • • 或者用 Python 库 schedule 更简洁
  • • 真正的服务器部署可以用 celery 或 APScheduler

总结:现在就开始

这篇文章的价值不在这5个脚本,而在它们背后的逻辑:

** Python不是用来"学"的,是用来"用"的。**

你不需要学完所有知识点才能做出东西。你只需要一个真实的需求,然后Google搜解决方法。

学再多不动手=没学。

现在立刻做三件事:

1️⃣ 选一个最打动你的场景,把代码复制到你的电脑上

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-04 05:17:41 HTTP/2.0 GET : https://f.mffb.com.cn/a/490969.html
  2. 运行时间 : 0.220784s [ 吞吐率:4.53req/s ] 内存消耗:4,708.75kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=a16b34a0a133f6a01fa1eed33b20420e
  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.001002s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.001392s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.007614s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000718s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.001385s ]
  6. SELECT * FROM `set` [ RunTime:0.000635s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.001439s ]
  8. SELECT * FROM `article` WHERE `id` = 490969 LIMIT 1 [ RunTime:0.001191s ]
  9. UPDATE `article` SET `lasttime` = 1783113461 WHERE `id` = 490969 [ RunTime:0.005119s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000697s ]
  11. SELECT * FROM `article` WHERE `id` < 490969 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.001513s ]
  12. SELECT * FROM `article` WHERE `id` > 490969 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.012476s ]
  13. SELECT * FROM `article` WHERE `id` < 490969 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.021227s ]
  14. SELECT * FROM `article` WHERE `id` < 490969 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.007743s ]
  15. SELECT * FROM `article` WHERE `id` < 490969 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.001677s ]
0.224453s