Home > Enterprise >  How to concatenate database elements to a string
How to concatenate database elements to a string

Time:04-17

I'm currently trying to take elements from a database to be displayed in a string by iterating through each row and adding it to an empty string.

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

Whenever the function is called I receive an error stating that "row" is a tuple and cannot be concatenated to a string. Using .join also creates an error.

CodePudding user response:

You can try this:

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