I am creating an email response to an overnight build, I want to get the last 50 lines from the results file and place it into a summary file. The code that I have done is below, can anyone help?
def email_success():
fp = open(results_file, 'r')
sum_file = (fp.readlines()[-50:])
fp.close()
myfile = open(result_summary,'w')
myfile.write(sum_file)
myfile.close()
I have got the error message below when trying this code:
Traceback (most recent call last):
File "email_success.py", line 76, in <module>
if __name__ == '__main__': myObject = email_success()
File "email_success.py", line 45, in email_success
myfile = open(result_summary,'w')
TypeError: coercing to Unicode: need string or buffer, tuple found
Thanks
The results summary is a variable that stores an address.
result_summary = (t, 'results_summary.txt')
Sorry made a stupid mistake, I forgot to add os.path.join
result_summary = os.path.join(t, 'results_summary.txt')
Thanks for the help
@alok It is a directory address, I forgot to add the os.join to make it one string. This is what was causing the error