I want to empty a global array variable in a function after using it but it shows that it is being shadowed and I don't know why. Here is my code am I doing something wrong?
import time
from tkinter import filedialog
import Main
attachments = []
def attach_file():
filename = filedialog.askopenfilename(initialdir='C:/', title='Select a file')
attachments.append(filename)
print(attachments)
if len(attachments) == 1:
Main.notif.config(fg="green", text="Attached " + str(len(attachments)) + " file")
elif len(attachments) > 1:
Main.notif.config(fg="green", text="Attached " + str(len(attachments)) + " files")
Main.root.update()
time.sleep(1)
Main.notif.config(text="")
filename2 = attachments[0]
filetype = filename2.split('.')
filetype = filetype[1]
if filetype == "jpg" or filetype == "JPG" or filetype == "png" or filetype == "PNG":
print("Image")
else:
print("doc")
attachments = [] <= error here
This is for attaching files of my Gmail sender app using Tkinter, SMTP lib, and email.message