python - Making SQLAlchemy records from a list -


fairly new python , new sqlalchemy. wondering how can use for loop make multiple sqlalchemy records list. here's simplified version of have.

class listitem(base):      __tablename__ = list_items     id = column(integer, primary_key=true)     item = column(string(50))  def list_to_listitem(list_of_things):      thing in list_of_things:          listitem = listitem()         listitem.item = thing 

i haven't yet run because there's lot more code still needs worked out, i'm under impression that, instead of creating record in list_items each thing in list_of_things, create 1 record assigned listitem overwrite every iteration of loop.

so how do this? said, i'm new python, i've heard factory functions don't understand which, @ least in name, sounds promising problem. in advance!

list comprehension?

list_items = [listitem(item=thing) thing in list_of_things] 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -