6.7 remarks
Sometimes there is a data type like "record" in Pasca and "data body" in C that is very useful. Set some data items. An empty class definition can be clearly displayed:
Class Employee:
Pass
John = Employee () # Create an empty employee record
# Fill the fields of the record
John. name = 'John Doe'
John. dept = 'computer lab'
John. salary = 1000
It is expected that a python code block of the special abstract round type can be passed to the class. This class can mimic that data type method. For example, if you have a function for formatting data from a file object, you can define a method that includes the read and readline methods to obtain data and pass it as a parameter.
The instance method object also has many attributes: m. _ self _ is a sorting object containing the method m (), and m. _ func _ Is the function object corresponding to the method.
6.8 exception is also a class
User-defined exceptions can also be defined by classes. This mechanism can be used to implement scaling exceptions.
Here there are two valid (syntax) forms to throw the statement:
Raise Class
Raise Instance
In the first form, the Class must be an instance of type or the Class inherits it. The first form is the following convenient method:
Raise Class ()
In an exception, the class and the exception are compatible. The exception here refers to the same class or a base class (but cannot be reversed-the exception statement in the traversal derived class cannot be compatible with the base class) for example, BCD will be printed in sequence.
Note that if the exception statement is flipped (before the occurrence of T), it will print out BBB, and the first exception statement that meets the requirements will be triggered.
When an error message for an unhandled exception is printed, the exception class name is printed. Next there are semicolons and spaces, and finally the built-in method is used to convert the instance into a string