Skip to content

Latest commit

 

History

History

ep006

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Very short one, I explain why I prefer type(x).__name__ vs x.__class__.__name__. thanks to @alikus for the question!

Interactive examples

Python

# python3.8
Location()
class C:
    @property
    def __class__(self):
        print('return custom type')
        return int

C().__class__
C().__class__.__name__
type(C())


# python2.7
class Old: pass
class New(object): pass

old = Old()
new = New()
type(new).__name__
type(old).__name__
type(old)

Bash

python3.8 -i t.py
# older version of python
python2.7 -i t.py