首页/ 接口索引/ 实战片段

无数据跳过而不是报错

if not img_find_in: skip_cnt += 1; continue —— 缺图就跳过并计数,不要让它中断整批任务。

场景

无数据跳过而不是报错

说明

if not img_find_in: skip_cnt += 1; continue —— 缺图就跳过并计数,不要让它中断整批任务。

Python 示例(可直接运行)

依赖 pywin32。示例假定 app / doc / page / layer 已就绪。 见「连接与初始化」
Python
# data : 从 json 读进来的记录列表(真实场景用 data = json.load(open(...)))
data = [{"title": "示例点", "img_path": ""}]      # 这里用假数据演示

skip = 0
done = 0

for item in data:
    img = item.get("img_path", "")
    if not img:                  # 缺图就跳过并计数,不要中断整批
        skip += 1
        print("跳过:", item.get("title", "无标题"))
        continue

    # ... 生成页面 ...
    done += 1

print(f"完成 {done} 条,跳过 {skip} 条")

关于本类:实战片段

把你代码里最有价值的部分抽成可复用函数,下次换项目直接粘。

同类其他接口