Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61997
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Subject | Re: Type of an object: ‘obj.__class__’ versus ‘type(obj)’ |
| Date | 2013-12-16 15:50 +1100 |
| References | <7wk3f5k1gm.fsf@benfinney.id.au> <l8lpp4$ito$1@ger.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4173.1387169433.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Type of an object: ‘obj.__class__’ versus ‘type(obj)’ Ben Finney <ben+python@benfinney.id.au> - 2013-12-16 15:50 +1100
csiph-web