如何将数据库元素连接到字符串

How to concatenate database elements to a string

我目前正在尝试通过遍历每一行并将其添加到空字符串中,从数据库中获取要显示在字符串中的元素。

    def PrintOverdueBooks():
        printed_message = ""
        for row in db_actions.GetAllOverdue():
            printed_message += row
            printed_message += " \n"
        print(printed_message)

每当调用该函数时,我都会收到一条错误消息,指出“行”是一个元组,不能连接到一个字符串。使用 .join 也会产生错误。

你可以试试这个:

def PrintOverdueBooks():
        printed_message = ''
        for row in db_actions.GetAllOverdue():
            stup = ''.join(row)
            printed_message += stup
        print(printed_message)