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

php - Admin SDK -- get information about the group -

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

Python Error - TypeError: input expected at most 1 arguments, got 3 -