Skip to content

adda bit about __class__ and subclassing to metaprogramming materials #178

Open
@PythonCHB

Description

@PythonCHB

In the Circle exercise, folks created methods that were not that friendly to subclassing.

use of the __class__ attribute could help with this:

In [61]: class C: 
    ...:     def test_name(self): 
    ...:         print("class name is:") 
    ...:         print(self.__class__.__name__) 
    ...:                                                                        

In [62]: c = C()                                                                

In [63]: c.test_name()                                                          
class name is:
C

similarly (and more importantly) for things like add, etc.

some notes and examples of this in the metaprogramming materials would be a good idea.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions