python - Uses for Nested Classes -
in scenarios nested classes useful, used lot in django,
class signupform(forms.modelform): class meta: model = signup fields = ['full_name','email']
but think same can achieved using other structures,so gain when use nested classes?
thanks
django unusual.
you see, django makes heavy use of behind-the-scenes feature called metaclass. in python 2, nested class cleanest , straightforward way of providing metaclass information isn't strictly part of class itself, such model form based on.
in python 3, possible metaclass accept additional keyword arguments, this:
class foo(bar, baz=qux): ...
those arguments passed directly metaclass constructor, , cleaner syntax nested class.
i not know whether django plans adopt syntax, backwards compatibility reasons, unlikely nested class syntax ever go away entirely.
Comments
Post a Comment