> On 23 Nov 2015, at 17:58, mzagr...@d.umn.edu wrote: > > Greetings, > > I'm new to SQLAlchemy - sorry if the answer to this question is obvious. > > I have a table with many fields. > > I've created the ORM mapping: > > Base = declarative_base() > class CallRecord(Base): > [stuff] > > I'd like to create the CallRecord object by passing a dictionary to the > constructor. Is that possible? > > call_record = CallRecord(my_dict) > > Thanks for any help! >
The declarative_base sets up an __init__ function that accepts initial values as keyword arguments, so you can write something like: call_record = CallRecord(a=123, b=456) In Python, you can call a function with keyword arguments from a dictionary using the “**” syntax: args = {‘a’: 123, ‘b’: 456} call_record = CallRecord(**args) Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.