Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adda bit about __class__ and subclassing to metaprogramming materials #178

Open
PythonCHB opened this issue Dec 5, 2018 · 0 comments
Open

Comments

@PythonCHB
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant