python读取\t\n的文件转换成html表格发送邮件(解决中文乱码问题)

【python读取\t\n的文件转换成html表格发送邮件(解决中文乱码问题)】html_format.py

#coding=utf-8 import sys reload(sys) sys.setdefaultencoding('utf-8') with open(sys.argv[1], 'r') as f: data = https://www.it610.com/article/f.readlines() print'' print (unicode('', encoding="utf-8")) for line in data: values = line.split('\t') print '' % (values[0],values[1],values[2],values[3]) print '
姓名性别年龄爱好
%s%s%s%s
'

linux中运行python脚本并将结果发送邮件:
result_data.txt为\t\n的文件
python ./html_format.py result_data.txt |formail -I "From: hlst@163.com" -I "MIME-Version:1.0" -I "Content-type:text/html; charset=utf8" -I "Subject:邮件主题"|/usr/sbin/sendmail -oi hlst1@163.com

    推荐阅读