Movatterモバイル変換


[0]ホーム

URL:


Sorry, we no longer support your browser
Please upgrade toMicrosoft Edge,Google Chrome, orFirefox. Learn more about ourbrowser support.
Skip to main content
Stack Overflow
  1. About
  2. For Teams
Loading…
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Return to Answer

deleted 1 character in body
Chankey Pathak
  • 21.8k
  • 12
  • 88
  • 138

type is actually ametaclass -- a class that creates another classes.Mostmetaclass are the subclasses oftype. Themetaclass receives thenew class as its first argument and provide access to class object with details as mentioned below:

>>> class MetaClass(type):...     def __init__(cls, name, bases, attrs):...         print ('class name: %s' %name )...         print ('Defining class %s' %cls)...         print('Bases %s: '%sbases%bases)...         print('Attributes')...         for (name, value) in attrs.items():...             print ('%s :%r' %(name, value))... >>> class NewClass(object, metaclass=MetaClass):...    get_choch='dairy'... class name: NewClassBases <class 'object'>: Defining class <class 'NewClass'>get_choch :'dairy'__module__ :'builtins'__qualname__ :'NewClass'

Note:

Notice that the class was not instantiated at any time; the simple act of creating the class triggered execution of themetaclass.

type is actually ametaclass -- a class that creates another classes.Mostmetaclass are the subclasses oftype. Themetaclass receives thenew class as its first argument and provide access to class object with details as mentioned below:

>>> class MetaClass(type):...     def __init__(cls, name, bases, attrs):...         print ('class name: %s' %name )...         print ('Defining class %s' %cls)...         print('Bases %s: '%sbases)...         print('Attributes')...         for (name, value) in attrs.items():...             print ('%s :%r' %(name, value))... >>> class NewClass(object, metaclass=MetaClass):...    get_choch='dairy'... class name: NewClassBases <class 'object'>: Defining class <class 'NewClass'>get_choch :'dairy'__module__ :'builtins'__qualname__ :'NewClass'

Note:

Notice that the class was not instantiated at any time; the simple act of creating the class triggered execution of themetaclass.

type is actually ametaclass -- a class that creates another classes.Mostmetaclass are the subclasses oftype. Themetaclass receives thenew class as its first argument and provide access to class object with details as mentioned below:

>>> class MetaClass(type):...     def __init__(cls, name, bases, attrs):...         print ('class name: %s' %name )...         print ('Defining class %s' %cls)...         print('Bases %s: '%bases)...         print('Attributes')...         for (name, value) in attrs.items():...             print ('%s :%r' %(name, value))... >>> class NewClass(object, metaclass=MetaClass):...    get_choch='dairy'... class name: NewClassBases <class 'object'>: Defining class <class 'NewClass'>get_choch :'dairy'__module__ :'builtins'__qualname__ :'NewClass'

Note:

Notice that the class was not instantiated at any time; the simple act of creating the class triggered execution of themetaclass.

updated the answer
Mushahid Khan
  • 2.8k
  • 1
  • 21
  • 32

type is actually ametaclass -- a class that creates another classes.Mostmetaclass are the subclasses oftype. Themetaclass receives thenew class as its first argument and provide access to class object with details as mentioned below:

>>> class MetaClass(type):...     def __init__(cls, name, bases, attrs):...         print ('class name: %s' %name )...         print ('Defining class %s' %cls)...         print('Bases %s: ' %sbases)...         print('Attributes')...         for (name, value) in attrs.items():...             print ('%s :%r' %(name, value))... >>> class NewClass(object, metaclass=MetaClass):...    get_choch='dairy'... class name: NewClassBases <class 'object'>: Defining class <class 'NewClass'>get_choch :'dairy'__module__ :'builtins'__qualname__ :'NewClass'

Note:

Notice that the class was not instantiated at any time; the simple act of creating the class triggered execution of themetaclass.

type is actually ametaclass -- a class that creates another classes.Mostmetaclass are the subclasses oftype. Themetaclass receives thenew class as its first argument and provide access to class object with details as mentioned below:

>>> class MetaClass(type):...     def __init__(cls, name, bases, attrs):...         print ('class name: %s' %name )...         print ('Defining class %s' %cls)...         print('Bases %s: ' %sbases)...         print('Attributes')...         for (name, value) in attrs.items():...             print ('%s :%r' %(name, value))... >>> class NewClass(object, metaclass=MetaClass):...    get_choch='dairy'... class name: NewClassBases <class 'object'>: Defining class <class 'NewClass'>get_choch :'dairy'__module__ :'builtins'__qualname__ :'NewClass'

Notice that the class was not instantiated at any time; the simple act of creating the class triggered execution of themetaclass.

type is actually ametaclass -- a class that creates another classes.Mostmetaclass are the subclasses oftype. Themetaclass receives thenew class as its first argument and provide access to class object with details as mentioned below:

>>> class MetaClass(type):...     def __init__(cls, name, bases, attrs):...         print ('class name: %s' %name )...         print ('Defining class %s' %cls)...         print('Bases %s: ' %sbases)...         print('Attributes')...         for (name, value) in attrs.items():...             print ('%s :%r' %(name, value))... >>> class NewClass(object, metaclass=MetaClass):...    get_choch='dairy'... class name: NewClassBases <class 'object'>: Defining class <class 'NewClass'>get_choch :'dairy'__module__ :'builtins'__qualname__ :'NewClass'

Note:

Notice that the class was not instantiated at any time; the simple act of creating the class triggered execution of themetaclass.

type is actually ametaclass -- a class that creates another classes.Mostmetaclass are the subclasses oftype. Themetaclass receives thenew class as its first argument and provide access to class object with details as mentioned below:

>>> class MetaClass(type):...     def __init__(cls, name, bases, attrs):...         print ('class name: %s' %name )...         print ('Defining class %s' %cls)...         print('Bases %s: ' %sbases)...         print('Attributes')...         for (name, value) in attrs.items():...             print ('%s :%r' %(name, value))... >>> class NewClass(object, metaclass=MetaClass):...    get_choch='dairy'...class name: NewClassBases <class 'object'>: Defining class <class 'NewClass'>get_choch :'dairy'__module__ :'builtins'__qualname__ :'NewClass'

Notice that the class was not instantiated at any time; the simple act of creating the class triggered execution of themetaclass.

type is actually ametaclass -- a class that creates another classes.Mostmetaclass are the subclasses oftype. Themetaclass receives thenew class as its first argument and provide access to class object with details as mentioned below:

>>> class MetaClass(type):...     def __init__(cls, name, bases, attrs):...         print ('class name: %s' %name )...         print ('Defining class %s' %cls)...         print('Bases %s: ' %sbases)...         print('Attributes')...         for (name, value) in attrs.items():...             print ('%s :%r' %(name, value))... >>> class NewClass(object, metaclass=MetaClass):...    get_choch='dairy'...

Notice that the class was not instantiated at any time; the simple act of creating the class triggered execution of themetaclass.

type is actually ametaclass -- a class that creates another classes.Mostmetaclass are the subclasses oftype. Themetaclass receives thenew class as its first argument and provide access to class object with details as mentioned below:

>>> class MetaClass(type):...     def __init__(cls, name, bases, attrs):...         print ('class name: %s' %name )...         print ('Defining class %s' %cls)...         print('Bases %s: ' %sbases)...         print('Attributes')...         for (name, value) in attrs.items():...             print ('%s :%r' %(name, value))... >>> class NewClass(object, metaclass=MetaClass):...    get_choch='dairy'...class name: NewClassBases <class 'object'>: Defining class <class 'NewClass'>get_choch :'dairy'__module__ :'builtins'__qualname__ :'NewClass'

Notice that the class was not instantiated at any time; the simple act of creating the class triggered execution of themetaclass.

grammar correction, formatting
Mushahid Khan
  • 2.8k
  • 1
  • 21
  • 32
Loading
Mushahid Khan
  • 2.8k
  • 1
  • 21
  • 32
Loading
lang-py

[8]ページ先頭

©2009-2025 Movatter.jp