Home > Blockchain >  How should I extract nested list for saving to database?
How should I extract nested list for saving to database?

Time:07-27

Exception:

Unpack operation not allowed in this context

My code for doing it:

def save_data_to_database(self):
    parsed_records = self.parse_sheet_data()
    for record in parsed_records:
        self.db.set_item(
            "sheet", #table name
            "id, number_of_order, cost, delivery_time" # These are fields in table
            f"{*record}" # Here I'm trying to unpack values, but I can't
        )

Value of 'parsed_records' looks like:

[['1', '1249708', '675', '24.05.2022'], ['2', '1182407', '214', '13.05.2022'], ['3', ...]]

If you see code in above, I want to unpack record with " * " but I can't. What should I do for saving records to db?

CodePudding user response:

See if this solve your problem

“,”.join(record)

CodePudding user response:

Check out this post about f-string unpacking if you'd like some alternatives.

  • Related