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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -