Unpacking Argument Lists and Instantiating WTForms objects from web.py
Posted
by
Morris Cornell-Morgan
on Stack Overflow
See other posts from Stack Overflow
or by Morris Cornell-Morgan
Published on 2012-08-29T07:01:08Z
Indexed on
2012/08/29
9:38 UTC
Read the original article
Hit count: 366
After a bit of searching, I've found that it's possible to instantiate a WTForms object in web.py using the following code:
form = my_form(**web.input())
web.input() returns a "dictionary-like" web.storage object, but without the double asterisks WTForms will raise an exception:
TypeError: formdata should be a multidict-type wrapper that supports the 'getlist' method
From the Python documentation I understand that the two asterisks are used to unpack a dictionary of named arguments. That said, I'm still a bit confused about exactly what is going on. What makes the web.storage object returned by web.input() "dictionary-like" enough that it can be unpacked by ** but not "dictionary-like" enough that it can be passed as-is to the WTForms constructor?
I know that this is an extremely basic question, but any advice to help a novice programmer would be greatly appreciated!
© Stack Overflow or respective owner