问一下 这个一直提醒 file_att[x] 下标超出 是文件不能用列表形式吗

files=os.listdir("./1月10")

file_att=[]
x=0
for file in files:
if '日出' in file:

    receivers = ‘@qq.com' #收件人的邮箱
    subject = '日出' #主题
    #初始化信息对象
    msg = MIMEMultipart()
    msg['Subject'] = subject
    msg['From'] = sender
    msg['To'] = receivers
    msg.attach(MIMEText('证券','plain','utf-8'))
    #构造附件1,传送当前目录下文件
    file_att[x] = MIMEText(open(f'./110/{file}','rb').read(),'base64','utf-8')   # rb以二进制方式读取
    file_att[x]["Content-Disposition"] = f'attachment; filename = "{file}"'
    #将附件添加到MIMEMultipart中
    msg.attach(file_att[x])
    x=x+1
    try:
        s.sendmail(sender,receivers,msg.as_string())
        print('发送成功')
    except Exception:
        print('发送失败')

img

file_att 是空的, 你的任何file_att[x] 都会提示下标越界。
大概理解你的逻辑, 可能应该这样写 , 先append 再修改列表最后一个元素

file_att.append(MIMEText(open(f'./1月10/{file}','rb').read(),'base64','utf-8') )
 file_att[-1]["Content-Disposition"] = f'attachment; filename = "{file}"'