找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 1947|回复: 0

[求助] 只显示process finished with excit code0却不执行代码

1

主题

1

帖子

1

积分

贫民

积分
1
rogerqzt 发表于 2023-4-12 13:16:00 | 显示全部楼层 |阅读模式
只显示process finished with excit code0

各位,我编写了一串代码,意图是:G:\桌面\1这个文件夹中搜索标题中含有“1”的excel文件。注意这个文件夹中有一堆excel其中有些文件格式是.xlsx有些是.xls。把找到的这个excel的完整标题打印出来。
GPT给我的代码是:
import os
import glob
import xlrd

# Define the directory to search in
dir_path = r'G:\桌面\1'

# Define the search query
query = '1'

# Search for Excel files in the directory
excel_files = glob.glob(os.path.join(dir_path, '*.xls*'))

# Loop through the Excel files and search for the query
for file_path in excel_files:
    # Open the Excel file
    try:
        workbook = xlrd.open_workbook(file_path)
    except (xlrd.biffh.XLRDError, PermissionError):
        continue
    # Get the first worksheet
    worksheet = workbook.sheet_by_index(0)
    # Check if the query is in the title or content
    if query in os.path.basename(file_path) or query in worksheet.name or query in str(worksheet.cell_value(0, 0)):
        # Print the title of the file
        print(os.path.basename(file_path))
结果却打印不出文件名只是显示:
Process finished with exit code 0

这是为何???说是运行成功了但是却并不执行???



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表