On 2023-08-04, Chris Angelico via Python-list wrote:
> On Sat, 5 Aug 2023 at 09:36, dn via Python-list
> wrote:
>
>> Faced with a situation where an argument may be a scalar-value or an
>> iterable, I'll presume the latter, eg throw it straight into a for-loop.
>> If that fails (because the argu
On Sat, 5 Aug 2023 at 09:36, dn via Python-list wrote:
> Faced with a situation where an argument may be a scalar-value or an
> iterable, I'll presume the latter, eg throw it straight into a for-loop.
> If that fails (because the argument is a scalar), use try-except to
> re-route the logic.
That
On 05/08/2023 11.18, Chris Angelico via Python-list wrote:
On Sat, 5 Aug 2023 at 09:08, dn via Python-list wrote:
On 03/08/2023 11.38, Jon Ribbens via Python-list wrote:
On 2023-08-02, dn wrote:
Can you please explain why a multi-part second-argument must be a tuple
and not any other form o
On Sat, 5 Aug 2023 at 09:08, dn via Python-list wrote:
>
> On 03/08/2023 11.38, Jon Ribbens via Python-list wrote:
> > On 2023-08-02, dn wrote:
> >> Can you please explain why a multi-part second-argument must be a tuple
> >> and not any other form of collection-type?
> >
> > The following commen
On 03/08/2023 11.38, Jon Ribbens via Python-list wrote:
On 2023-08-02, dn wrote:
Can you please explain why a multi-part second-argument must be a tuple
and not any other form of collection-type?
The following comment may hold a clue:
if (PyTuple_Check(cls)) {
/* Not a general
On 2023-08-02, dn wrote:
> Can you please explain why a multi-part second-argument must be a tuple
> and not any other form of collection-type?
The following comment may hold a clue:
if (PyTuple_Check(cls)) {
/* Not a general sequence -- that opens up the road to
recursio
On 03Aug2023 10:14, dn wrote:
Can you please explain why a multi-part second-argument must be a
tuple and not any other form of collection-type?
The signature is: isinstance(object, classinfo)
leading to "classinfo" of:
1/ a single class/type, eg int
2/ a tuple of same, eg ( int, str, )
3/ a
On Fri, Aug 28, 2015 at 1:02 PM, Steven D'Aprano wrote:
> On Fri, 28 Aug 2015 12:33 am, Chris Angelico wrote:
>
>> On Thu, Aug 27, 2015 at 10:59 PM, Steven D'Aprano
>> wrote:
>>> On Thu, 27 Aug 2015 09:14 am, Chris Angelico wrote:
>>>
On Thu, Aug 27, 2015 at 9:12 AM, Chris Angelico
wro
On Fri, 28 Aug 2015 12:33 am, Chris Angelico wrote:
> On Thu, Aug 27, 2015 at 10:59 PM, Steven D'Aprano
> wrote:
>> On Thu, 27 Aug 2015 09:14 am, Chris Angelico wrote:
>>
>>> On Thu, Aug 27, 2015 at 9:12 AM, Chris Angelico
>>> wrote:
Or is there a magic __isinstance__
>>>
>>> Argh, keyed th
On Thu, Aug 27, 2015 at 10:59 PM, Steven D'Aprano wrote:
> On Thu, 27 Aug 2015 09:14 am, Chris Angelico wrote:
>
>> On Thu, Aug 27, 2015 at 9:12 AM, Chris Angelico wrote:
>>> Or is there a magic __isinstance__
>>
>> Argh, keyed the wrong thing and sent the post prematurely. Meant to say:
>>
>> Or
On Thu, 27 Aug 2015 09:14 am, Chris Angelico wrote:
> On Thu, Aug 27, 2015 at 9:12 AM, Chris Angelico wrote:
>> Or is there a magic __isinstance__
>
> Argh, keyed the wrong thing and sent the post prematurely. Meant to say:
>
> Or is there a magic __instancecheck__ method somewhere that I'm not
On Thu, 27 Aug 2015 09:12:55 +1000, Chris Angelico wrote:
>
> You're omitting some context here, but after poking around with your
> module a bit, I'm guessing you created bf somewhat thus?
>
bf = bitfield.make_bf("bf", (("asdf",bitfield.c_uint,2),))
bf
>
bf.__mro__
> (, , '_ctyp
On Thu, Aug 27, 2015 at 9:12 AM, Chris Angelico wrote:
> Or is there a magic __isinstance__
Argh, keyed the wrong thing and sent the post prematurely. Meant to say:
Or is there a magic __instancecheck__ method somewhere that I'm not aware of?
ChrisA
--
https://mail.python.org/mailman/listinfo/
On Thu, Aug 27, 2015 at 7:21 AM, Rob Gaddi
wrote:
> I'm running into some strangeness trying to work with the bitfield module
> from my ctypes-bitfield package (on PyPi). I'm trying to use isinstance
> (), and it's kinda sorta lying to me.
>
> - IPython session (Python 3.4 under Linux) --
On 8/26/2015 5:21 PM, Rob Gaddi wrote:
I'm running into some strangeness trying to work with the bitfield module
from my ctypes-bitfield package (on PyPi). I'm trying to use isinstance
(), and it's kinda sorta lying to me.
isinstace(inst, klass) is implemented as
klass.__instancecheck__(inst)
Duncan Booth, 08.11.2012 14:58:
> Ulrich Eckhardt wrote:
>> If possible, I'm looking for a solution that works for Pythons 2 and 3,
>> since I'm not fully through the conversion yet and have clients that
>> might use the older snake for some time before shedding their skin.
>>
>> Suggestions?
>
Ulrich Eckhardt wrote:
> If possible, I'm looking for a solution that works for Pythons 2 and 3,
> since I'm not fully through the conversion yet and have clients that
> might use the older snake for some time before shedding their skin.
>
> Suggestions?
Why bother checking types at all?
def
On Thu, 08 Nov 2012 13:05:22 +0100, Ulrich Eckhardt wrote:
> Firstly, I have code that allows either a file or a string representing
> its content as parameter. If the parameter is a file, the content is
> read from the file. In Python 2, I used "isinstance(p, file)" to
> determine whether the par
Ulrich Eckhardt wrote:
> Hi!
>
> I have two problems that are related and that I'd like to solve together.
>
> Firstly, I have code that allows either a file or a string representing
> its content as parameter. If the parameter is a file, the content is
> read from the file. In Python 2, I used
On Thu, Nov 8, 2012 at 11:05 PM, Ulrich Eckhardt
wrote:
> Firstly, I have code that allows either a file or a string representing its
> content as parameter. If the parameter is a file, the content is read from
> the file. In Python 2, I used "isinstance(p, file)" to determine whether the
> parame
On 2012-11-08 12:05, Ulrich Eckhardt wrote:
Hi!
I have two problems that are related and that I'd like to solve together.
Firstly, I have code that allows either a file or a string representing
its content as parameter. If the parameter is a file, the content is
read from the file. In Python 2,
On 06/23/2010 08:39 AM, Satish Eerpini wrote:
>
>
> I want to test whether an object is an instance of any
> user-defined
> class. "isinstance" is less helpful than one would expect.
>
> >>> import types
> >>> class foo() : # define dummy class
>
>
>I want to test whether an object is an instance of any user-defined
>> class. "isinstance" is less helpful than one would expect.
>>
>> >>> import types
>> >>> class foo() : # define dummy class
>> ... pass
>> ...
>> >>> x = foo()
>> >>>
>> >>> type(x)
>>
>> >>>
>> >>> isinstanc
En Tue, 22 Jun 2010 23:45:07 -0300, John Nagle
escribió:
I want to test whether an object is an instance of any user-defined
class. "isinstance" is less helpful than one would expect.
>>> import types
>>> class foo() : # define dummy class
... pass
...
>>> x = foo()
>>>
>>> type
On 6/22/2010 8:13 PM, Ben Finney wrote:
John Nagle writes:
I want to test whether an object is an instance of any user-defined
class. "isinstance" is less helpful than one would expect.
Right. The type hierarchy is now unified; there's essentially no
difference in later Python versions b
John Nagle writes:
> I want to test whether an object is an instance of any user-defined
> class. "isinstance" is less helpful than one would expect.
Right. The type hierarchy is now unified; there's essentially no
difference in later Python versions between user-defined types and
built-in ty
Rolando Espinoza La Fuente a écrit :
On Fri, Mar 5, 2010 at 2:32 PM, mk wrote:
Arnaud Delobelle wrote:
1 == True
True
0 == False
True
So what's your question?
Well nothing I'm just kind of bewildered: I'd expect smth like that in Perl,
but not in Python.. Although I can understand the ra
On 2010-03-05 17:48 PM, Jack Diederich wrote:
On Fri, Mar 5, 2010 at 6:09 PM, Steven D'Aprano
wrote:
On Fri, 05 Mar 2010 15:58:01 -0500, Jack Diederich wrote:
So, the pythonic way to check for True/False should be:
1 is True
False
Why do you need to check for True/False?
You should n
On Fri, Mar 5, 2010 at 1:51 PM, Terry Reedy wrote:
> On 3/5/2010 1:54 PM, Jean-Michel Pichavant wrote:
>> Steven D'Aprano wrote:
>
>> Despite there are good reasons for bool to be int, the newcomer 'wtf'
>> reaction at first glance is legitimate.
>> Starting python from scratch, booleans would hav
On Fri, Mar 5, 2010 at 6:09 PM, Steven D'Aprano
wrote:
> On Fri, 05 Mar 2010 15:58:01 -0500, Jack Diederich wrote:
>
So, the pythonic way to check for True/False should be:
>>> 1 is True
False
>>>
>>> Why do you need to check for True/False?
>>>
>>>
>> You should never check for
On Fri, 05 Mar 2010 15:58:01 -0500, Jack Diederich wrote:
>>> So, the pythonic way to check for True/False should be:
>>>
>> 1 is True
>>> False
>>
>> Why do you need to check for True/False?
>>
>>
> You should never check for "is" False/True but always check for
> equality. The reason is tha
On 2010-03-05 14:58 PM, Jack Diederich wrote:
On Fri, Mar 5, 2010 at 2:54 PM, Steven D'Aprano
wrote:
On Fri, 05 Mar 2010 15:01:23 -0400, Rolando Espinoza La Fuente wrote:
On Fri, Mar 5, 2010 at 2:32 PM, mk wrote:
Arnaud Delobelle wrote:
1 == True
True
0 == False
True
So what's you
On 3/5/2010 1:54 PM, Jean-Michel Pichavant wrote:
Steven D'Aprano wrote:
Despite there are good reasons for bool to be int, the newcomer 'wtf'
reaction at first glance is legitimate.
Starting python from scratch, booleans would have not been a subclass of
int (just guessing though), 'cause it
On 3/5/2010 1:30 PM, MRAB wrote:
mk wrote:
>>> isinstance(False, int)
True
>>>
>>> isinstance(True, int)
True
Huh?
>>>
>>> issubclass(bool, int)
True
Huh?!
Python didn't have Booleans originally, 0 and 1 were used instead. When
bool was introduced it was made a subclass of int so that exist
On Fri, Mar 5, 2010 at 2:54 PM, Steven D'Aprano
wrote:
> On Fri, 05 Mar 2010 15:01:23 -0400, Rolando Espinoza La Fuente wrote:
>
>> On Fri, Mar 5, 2010 at 2:32 PM, mk wrote:
>>> Arnaud Delobelle wrote:
>>>
>>> 1 == True
True
>>>
>>> 0 == False
True
So wha
On Fri, 05 Mar 2010 15:01:23 -0400, Rolando Espinoza La Fuente wrote:
> On Fri, Mar 5, 2010 at 2:32 PM, mk wrote:
>> Arnaud Delobelle wrote:
>>
>> 1 == True
>>>
>>> True
>>
>> 0 == False
>>>
>>> True
>>>
>>> So what's your question?
>>
>> Well nothing I'm just kind of bewildered: I'd
Rolando Espinoza La Fuente wrote:
Doesn't have side effects not knowing that False/True are ints?
It does, in fact I was wondering why my iterator didn't work until I
figured issubclass(bool, int) is true.
Regards,
mk
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, Mar 5, 2010 at 2:32 PM, mk wrote:
> Arnaud Delobelle wrote:
>
> 1 == True
>>
>> True
>
> 0 == False
>>
>> True
>>
>> So what's your question?
>
> Well nothing I'm just kind of bewildered: I'd expect smth like that in Perl,
> but not in Python.. Although I can understand the rat
Steven D'Aprano wrote:
On Fri, 05 Mar 2010 18:14:16 +0100, mk wrote:
isinstance(False, int)
True
>>>
>>> isinstance(True, int)
True
Huh?
Yes. Do you have an actual question?
>>> issubclass(bool, int)
True
Huh?!
Exactly.
Bools are a late-comer to Python.
Arnaud Delobelle wrote:
1 == True
True
0 == False
True
So what's your question?
Well nothing I'm just kind of bewildered: I'd expect smth like that in
Perl, but not in Python.. Although I can understand the rationale after
skimming PEP 285, I still don't like it very much.
Regards,
mk
mk wrote:
>>> isinstance(False, int)
True
>>>
>>> isinstance(True, int)
True
Huh?
>>>
>>> issubclass(bool, int)
True
Huh?!
Python didn't have Booleans originally, 0 and 1 were used instead. When
bool was introduced it was made a subclass of int so that existing code
wouldn't break.
--
h
On Fri, Mar 5, 2010 at 2:00 PM, Steve Holden wrote:
[...]
>
> Just a brainfart from the BDFL - he decided (around 2.2.3, IIRC) that it
> would be a good ideal for Booleans to be a subclass of integers.
>
I would never figured out
>>> bool.__bases__
(,)
Doesn't have side effects not knowing tha
On Fri, 05 Mar 2010 18:14:16 +0100, mk wrote:
isinstance(False, int)
> True
> >>>
> >>> isinstance(True, int)
> True
>
> Huh?
Yes. Do you have an actual question?
> >>> issubclass(bool, int)
> True
>
> Huh?!
Exactly.
Bools are a late-comer to Python. For historical and implementatio
On Fri, Mar 5, 2010 at 9:14 AM, mk wrote:
> >>> isinstance(False, int)
> True
> >>>
> >>> isinstance(True, int)
> True
>
> Huh?
>
> >>>
> >>> issubclass(bool, int)
> True
>
> Huh?!
>
Huh, what?
http://www.python.org/dev/peps/pep-0285/
--S
--
http://mail.python.org/mailman/listinfo/python-list
mk writes:
isinstance(False, int)
> True
isinstance(True, int)
> True
>
> Huh?
>
issubclass(bool, int)
> True
>
> Huh?!
>
> Regards,
> mk
Yes, and:
>>> True + False
1
In fact:
>>> 1 == True
True
>>> 0 == False
True
So what's your question?
--
Arnaud
--
http://mail
mk wrote:
isinstance(False, int)
> True
isinstance(True, int)
> True
>
> Huh?
>
issubclass(bool, int)
> True
>
> Huh?!
>
>>> 3+True
4
>>> 3+False
3
>>>
Just a brainfart from the BDFL - he decided (around 2.2.3, IIRC) that it
would be a good ideal for Booleans to be a s
Art wrote:
I have the following problem:
ipdb> p type(self)
ipdb> isinstance(self, component.BiasComponent)
False
I thought that isinstance(obj, type(obj)) == True.
Yes, but that is not what you entered ;-).
The name 'component.BiasComponent' is not bound to type(self),
but to another objec
On Wed, Jun 24, 2009 at 7:57 AM, Art wrote:
> I have the following problem:
>
> ipdb> p type(self)
>
>
> ipdb> isinstance(self, component.BiasComponent)
> False
>
> I thought that isinstance(obj, type(obj)) == True.
>
> The specific problem is when I try to call the super of a class and it
> only
48 matches
Mail list logo