/AttributeError:“list”对象没有属性“split”

2024-03-28 10:53:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我在拆分列表中的字符串时遇到问题。代码应该将列表中的字符串拆分,然后将它们输入到邮件中发送。在

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)

这是输入测量值的示例测量值

^{pr2}$

我期望输出如下:

[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)]

Tags: none列表datetimetimebackchannelnowsplit