I wonder why the third line in Snippet B would trigger an error. My understanding is in the second line in Snippet B (and A), I created a class variable (not a class instance) cls_obj
whose type/class name is Duck
. It's like
class Duck(...):
...Code goes here
cls_obj=Duck
So I expected snippet A and B would both work, however, snippet B failed! What has gone wrong?
# Snippet A
from collections import namedtuple
cls_obj=namedtuple('Duck', 'bill tail')
duck = cls_obj(bill='wide orange', tail='long')
# Snippet B
from collections import namedtuple
cls_obj=namedtuple('Duck', 'bill tail')
duck = Duck(bill='wide orange', tail='long')