[英]Why doesn't my program give output or even error in python
没有给任何 output 我该怎么办?
for files in os.listdir(dir):
if files[-4::] == 'xlsx':
file_1 = pd.ExcelFile((os.path.join(dir,files)),engine='openpyxl')
print('Path of File: ', os.path.join(dir,files))
print('Student Number: ', pd.read_excel(file_1, sheet_name=0).iloc[0,1])
for names in sheets_names:
sheet = file_1.sheet_names.index(names)
print('Sheet: ', file_1.sheet_names[sheet])
file_original = pd.read_excel(file_1, sheet_name=sheet,engine='openpyxl',header=0,usecols=None)
df=file_original.copy()
print(df)
稍微扩展一下 Ssayan 的评论
我可以看到两个可能的原因你没有得到任何 output
dir
中没有文件dir
中有文件:没有文件满足您的 if 语句在这两种情况下,都不会产生 output。
我建议打印os.listdir(dir)
并查看有哪些文件。 还要打印dir
看路径是否正确。 还要验证您的文件具有正确的扩展名(而不是例如 xls 或 ods)。
如果你想要错误消息,你必须自己添加它们。 你可以这样做:
file_found = False
for files in os.listdir(dir):
print(f"processing file: '{files}'")
if files[-4::] == 'xlsx':
file_found = True
else:
print(f"current file does not end with xlsx. Its last 4 chars are: '{files[-4:]}'")
if not file_found:
print("ERROR: There were no files with ending xlsx")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.