Provided that the rest of your code works to your satisfaction, you can use the CSV module to write your desired file.
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
folder = outlook.Folders.Item("Test Folder")
inbox = folder.Folders.Item("Inbox")
msg = inbox.Items
f = open("testfile.txt", "w", newline="")
writer = csv.writer(f)
writer.writerow(["emailSubject", "sender", "senderEmailAddress"])
# Process
for x in msg:
senderEmail = x.SenderEmailAddress
sender = x.Sender
subject = x.Subject
writer.writerow([subject, sender, senderEmail])
f.close()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…