problem with os.remove in python mail file

A forum for general discussion of the Python programming language.

problem with os.remove in python mail file

Postby wufnalkey » Wed Jan 15, 2014 9:36 pm

Code: Select all
import smtplib
import datetime
import os


today=datetime.date.today()
month=today.strftime('%m')
year=today.strftime('%Y')
day=today.strftime('%d')
day=int(day)
day=day-1
day=str(day)
fname = "D:\\datas"+year+month+day+".htm"
infile = open(fname, 'r')
data = infile.read()
fromaddr = "XXXXX@gmail.com"
toaddrs  = "XXXXXX@gmail.com"




server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login("XXXXXXX","XXXXXXX")
server.sendmail(fromaddr, toaddrs, data)
server.quit()

os.remove(fname)

the code supposed to transfer a .htm document to an email and than to delete it.

the only problem with that script is that the os.remove() in the end just not working, tried it in seperate file and it worked perfectly fine.
anyone has an idea how to fix this problem?
wufnalkey
 
Posts: 1
Joined: Wed Jan 15, 2014 9:30 pm

Re: problem with os.remove in python mail file

Postby Yoriz » Wed Jan 15, 2014 10:16 pm

Try closing the file you have open before removing it.
Code: Select all
infile.close()
os.remove(fname)
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 1052
Joined: Fri Feb 08, 2013 1:35 am
Location: UK


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 2 guests