Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61997 > unrolled thread

Re: Type of an object: ‘obj.__class__’ versus ‘type(obj)’

Started byBen Finney <ben+python@benfinney.id.au>
First post2013-12-16 15:50 +1100
Last post2013-12-16 15:50 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Type of an object: ‘obj.__class__’ versus ‘type(obj)’ Ben Finney <ben+python@benfinney.id.au> - 2013-12-16 15:50 +1100

#61997 — Re: Type of an object: ‘obj.__class__’ versus ‘type(obj)’

FromBen Finney <ben+python@benfinney.id.au>
Date2013-12-16 15:50 +1100
SubjectRe: Type of an object: ‘obj.__class__’ versus ‘type(obj)’
Message-ID<mailman.4173.1387169433.18130.python-list@python.org>
Ned Batchelder <ned@nedbatchelder.com> writes:

> Generally, my answer would be, "You probably don't need the type as
> much as you think you do."  
> […]
> Also, don't overlook isinstance().

Agreed.

> But when you do need it, type(x) is better than x.__class__, simply
> because we should always favor builtin functions over direct access of
> dunder-names where possible.

Thanks.

Should we expect (ignoring pathological cases) the assertion
‘type(obj) is obj.__class__’ to hold true? If not, under what
circumstances would it be sensible for those to differ?

-- 
 \       “For fast acting relief, try slowing down.” —Jane Wagner, via |
  `\                                                       Lily Tomlin |
_o__)                                                                  |
Ben Finney

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web