type-checking / type() function
rdickins at usaor.net
Tue Aug 20 15:28:32 EDT 2002
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
More information about the Python-list