From: Rutger V. <rv...@sf...> - 2005-10-21 11:40:14
|
I think what you want to do, in general, is look at *behaviour*, not at *identity*. If something walks like a duck (or array), and quacks like a duck (or array) for our intents and purposes it is a duck (or array). I suppose tastes differ, but to me it seems that duck-typing is more OO than "real" type/instance checking. The type of an object is an implementation detail, what matters is how it presents itself to the world. Guy K. Kloss wrote: >Hi Christ, > >On Friday, October 21, 2005 02:26 pm, christophe blin wrote: > > >>I am doing the following to identify when the parameter is an array >>and when it is not: >> if str(type(b)) == 'org.python.core.PyArray': >> >>I would like to know if there is another (more standard) way to do >>this >> >> > >in CPython I usually use isinstance() for those checks. If, for >instance, I want to check a passed argument for whether it is of a >suitable sequence type I use something like this: > >if isinstance(aces, list) or isinstance(aces, tuple): > # do it here ... > >You should check, whether that would work in Jython as well, never done >it in Jython myself, though. > >HTH, > >Guy > > > -- ++++++++++++++++++++++++++++++++++++++++++++++++++++ Rutger Vos, PhD. candidate Department of Biological Sciences Simon Fraser University 8888 University Drive Burnaby, BC, V5A1S6 Phone: 604-291-5625 Fax: 604-291-3496 Personal site: http://www.sfu.ca/~rvosa FAB* lab: http://www.sfu.ca/~fabstar Bio::Phylo: http://search.cpan.org/~rvosa/Bio-Phylo/ ++++++++++++++++++++++++++++++++++++++++++++++++++++ |