我在拆分列表中的字符串时遇到问题。该代码应该拆分列表中的字符串,然后将其输入到消息中以通过电子邮件发送。
def report(db_connection, hours_back):
#create a string out of all the measurements
time_now = datetime.datetime.now()
time_before = time_now - datetime.timedelta(hours=hours_back)
measurements = select_measurements_for_report(db_connection, hours_back)
split = measurements.split(',')
new_measurements = [split.split() for i in sents if i]
message = """\
Report data from {0} to {1}
{2}
""".format(time_before, time_now, new_measurements)
send_mail(message)
这是输入到测量中的示例测量
[Measurement(measurementID=1, startTime=1555960632.4752572, endTime=1555960832.4752572, duration=100.0, channel=1, dataCounters=None), Measurement(measurementID=2, startTime=1555960532.4752572, endTime=1555960732.4752572, duration=100.0, channel=1, dataCounters=None), Measurement(measurementID=3, startTime=1555960432.4752572, endTime=1555960632.4752572, duration=100.0, channel=1, dataCounters=None), Measurement(measurementID=4, startTime=1555960332.4752572, endTime=1555960532.4752572, duration=100.0, channel=1, dataCounters=None)]
我期望输出如下:
[measurementID=1, startTime=1555960632.4752572, endTime=1555960832.4752572, duration=100.0, channel=1, dataCounters=None), measurementID=2, startTime=1555960532.4752572, endTime=1555960732.4752572, duration=100.0, channel=1, dataCounters=None), measurementID=3, startTime=1555960432.4752572, endTime=1555960632.4752572, duration=100.0, channel=1, dataCounters=None), measurementID=4, startTime=1555960332.4752572, endTime=1555960532.4752572, duration=100.0, channel=1, dataCounters=None)]