oop - Shouldn't __metaclass__ force the use of a metaclass in Python? -
I am trying to learn about MetaLaces in Python. I get the main idea, but I can not seem to activate the mechanism. As I understand it, you can specify M to be able to set the MX at global or class level and by setting the __ MetaClass __ as the Metaclace during the creation of the class. To test it, I wrote the following program:
p = print class M (type): def __init __ (* args): type .__ init __ (* args) print ("rain In Spain ") P (1) Classroom META: __MetCalus_ = MP (2) __MetaCLASS__ = M Class GlobalMeta: Pass P (3) M ('no meter2', (), {}) P (4) < However, when I run it, I get the following output: C: \ Documents and Settings \ Daniel Wong \ Desktop> Python --version Python 3.0. 1 C: \ Documents and Settings \ Daniel Wong \ Desktop> Python meta.py rain 3 in Spain 4 Should not I see "rain in Spain" after 1 and 2? What's going on here?
In metadars (which you are using) in Python 3, a keyword parameter is specified by the class In the definition of:
class classmate (metaclass = m): pass
a __ metalex __ class properties or global variables Specifying is the old syntax from Python 2.x and is no longer supported. Also see and.
Comments
Post a Comment