Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to concatenate database elements to a string

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can try this:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading