FAQ
class C: pass
if type(inst)==type(C()): #is a class instance
className = inst.__class__ #get the class name
if isinstance(inst,C): #test whether instance of
class or subclass
...

"Ben S" <newsgroups2002 at thedarkness.fsnet.co.uk> wrote in message
news:ajtshe$jal$1 at news8.svr.pol.co.uk...
How can I implement rudimentary type-checking in the functions where I
need it? (Where user Python code passes parameters to my Python code,
for example.) I figure the type() function is what I need, but I can't
find much information on what exactly it returns, and 'InstanceType'
isn't specific enough. Is there a way of getting the class name from an
instance?

--
Kylotan
http://pages.eidosnet.co.uk/kylotan

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 4 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedAug 20, '02 at 4:59p
activeAug 22, '02 at 1:21p
posts4
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase