Re: Need instruction on how to use isinstance

2010-06-30 Thread alex23
Hans Mulder wrote: > There's also: hasattr(, '__call__').  It works in both 2.x and 3.x. Good work, Hans. I do find that to be a more pythonic approach, personally, being more concerned with an object's ability than its abstract type. -- http://mail.python.org/mailman/listinfo/python-list

Re: Need instruction on how to use isinstance

2010-06-30 Thread Hans Mulder
alex23 wrote: Stephen Hansen wrote: P.S. The removal of callable is something I don't understand in Python 3: while generally speaking I do really believe and use duck typing, I too have on occassion wanted to dispatch based on 'is callable? do x'. Sometimes its not convenient to do so via duck

Re: Need instruction on how to use isinstance

2010-06-27 Thread Stephen Hansen
On 6/27/10 10:09 PM, alex23 wrote: Stephen Hansen wrote: What the hell? When did that show up? o.O (Did I not pay attention enough during the ABC conversations? It seemed so boring). The PEPs& post-release docs detailing Py3 changes were worth reading, it's noted in the sections on changes t

Re: Need instruction on how to use isinstance

2010-06-27 Thread Chris Rebert
On Sun, Jun 27, 2010 at 9:54 PM, Stephen Hansen wrote: > On 6/27/10 9:30 PM, alex23 wrote: >> Stephen Hansen  wrote: >>> P.S. The removal of callable is something I don't understand in Python >>> 3: while generally speaking I do really believe and use duck typing, I >>> too have on occassion wante

Re: Need instruction on how to use isinstance

2010-06-27 Thread alex23
Stephen Hansen wrote: > What the hell? When did that show up? o.O (Did I not pay attention > enough during the ABC conversations? It seemed so boring). The PEPs & post-release docs detailing Py3 changes were worth reading, it's noted in the sections on changes to built-ins: http://www.python.org

Re: Need instruction on how to use isinstance

2010-06-27 Thread Stephen Hansen
On 6/27/10 9:47 PM, Chris Rebert wrote: There's always: isinstance(, collections.Callable) Why in Guido's name is that in the collections module of all places? What hath callability to do with container objects? What he said! Minus the blasphemy. It's Benevolent _Dictator_ For Life. Not Bene

Re: Need instruction on how to use isinstance

2010-06-27 Thread Stephen Hansen
On 6/27/10 9:30 PM, alex23 wrote: Stephen Hansen wrote: P.S. The removal of callable is something I don't understand in Python 3: while generally speaking I do really believe and use duck typing, I too have on occassion wanted to dispatch based on 'is callable? do x'. Sometimes its not convenie

Re: Need instruction on how to use isinstance

2010-06-27 Thread Chris Rebert
On Sun, Jun 27, 2010 at 9:30 PM, alex23 wrote: > Stephen Hansen wrote: >> P.S. The removal of callable is something I don't understand in Python >> 3: while generally speaking I do really believe and use duck typing, I >> too have on occassion wanted to dispatch based on 'is callable? do x'. >> S

Re: Need instruction on how to use isinstance

2010-06-27 Thread alex23
Stephen Hansen wrote: > P.S. The removal of callable is something I don't understand in Python > 3: while generally speaking I do really believe and use duck typing, I > too have on occassion wanted to dispatch based on 'is callable? do x'. > Sometimes its not convenient to do so via duck typing.

Re: Need instruction on how to use isinstance

2010-06-27 Thread Stephen Hansen
On 6/27/10 8:04 PM, Steven W. Orr wrote: On 6/27/2010 10:25 PM, Stephen Hansen wrote: On 6/27/10 7:09 PM, Steven W. Orr wrote: So, my question is, what value can I use as the 2nd arg to isinstance to see if foo is a function? And while I'm on the subject, what types does isinstance not support?

Re: Need instruction on how to use isinstance

2010-06-27 Thread Steven W. Orr
On 6/27/2010 10:25 PM, Stephen Hansen wrote: > On 6/27/10 7:09 PM, Steven W. Orr wrote: >> So, my question is, what value can I use as the 2nd arg to isinstance >> to see if >> foo is a function? And while I'm on the subject, what types does >> isinstance not >> support? > > Does it have to be a f

Re: Need instruction on how to use isinstance

2010-06-27 Thread MRAB
Steven W. Orr wrote: I need to test an argument for a few different types. I'm calling my function like this arf = MyFunc(list) What I want to do is to test for whether something is a string, tuple, list or function. It's that last one that's causing me a problem. if isinstance(arg, (str, tup

Re: Need instruction on how to use isinstance

2010-06-27 Thread Stephen Hansen
On 6/27/10 7:09 PM, Steven W. Orr wrote: So, my question is, what value can I use as the 2nd arg to isinstance to see if foo is a function? And while I'm on the subject, what types does isinstance not support? Does it have to be a function? -- There's quite a few things which are function-y en

Need instruction on how to use isinstance

2010-06-27 Thread Steven W. Orr
I need to test an argument for a few different types. I'm calling my function like this arf = MyFunc(list) What I want to do is to test for whether something is a string, tuple, list or function. It's that last one that's causing me a problem. if isinstance(arg, (str, tuple, list)): No problem