python - Unpacking dictionary into model -


when unpacking ** need have same arguments constructor?

what mean is, if have additional item in dictionary, should ignored, need pop item? trying unpack everything, , expecting item excluded, getting error:

  __init__() got unexpected keyword argument 

nagative = negativesentimentanalysis(**negative_items) 

class negativesentimentanalysis(db.model):     id = db.column(db.integer, primary_key=true)     sentiment = db.column(db.string(500))     topic = db.column(db.string(500))      def __init__(self, sentiment=none, topic=none):         self.sentiment = user_id         self.topic = topic 

you can have __init__ accept keyword arguments:

    def __init__(self, sentiment=none, topic=none, **kw): 

this cause leftover arguments collected in kw method can ignore. however, comes caveat may have other code construct object may need fail.

alternatively filter out arguments noted in other answer.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -