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
)
will be mono-dimensional 99.9% of the time.
NB having said that, the underlying mechanism *is* multi-dimensional:
"direct, indirect, or virtual) subclass thereof"
(https://docs.python.org/3/library/functions.html#isinstance)
Further: the 'rules' say: "cl
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, s
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 union type, eg
n-list@python.org
Asunto: Re: try..except or type() or isinstance()?
On Sun, 16 Aug 2020 09:40:12 +0200
Manfred Lotz wrote:
> On Sat, 15 Aug 2020 12:20:48 -0400
> Dennis Lee Bieber wrote:
>
> > On Sat, 15 Aug 2020 15:31:56 +0200, Manfred Lotz
> > declaimed the following:
&
On Sun, 16 Aug 2020 09:40:12 +0200
Manfred Lotz wrote:
> On Sat, 15 Aug 2020 12:20:48 -0400
> Dennis Lee Bieber wrote:
>
> > On Sat, 15 Aug 2020 15:31:56 +0200, Manfred Lotz
> > declaimed the following:
> >
> > >On Sat, 15 Aug 2020 11:47:03 +0200
> > >Sibylle Koczian wrote:
> > >
> >
On 15 Aug 2020 14:49:48 GMT
r...@zedat.fu-berlin.de (Stefan Ram) wrote:
> Manfred Lotz writes:
> >Here a minimal example
>
> main.py
>
> source="""
> sehr gut
> 1
> """[ 1: -1 ].split( "\n" )
>
> class grades:
> names =[ "sehr gut" ]
> @staticmethod
> def is_numeric( text ):
>
On Sat, 15 Aug 2020 12:20:48 -0400
Dennis Lee Bieber wrote:
> On Sat, 15 Aug 2020 15:31:56 +0200, Manfred Lotz
> declaimed the following:
>
> >On Sat, 15 Aug 2020 11:47:03 +0200
> >Sibylle Koczian wrote:
> >
>
> >> if the value comes from a file, isn't it a
> >> string in any case? A string
On Sat, 15 Aug 2020 11:47:03 +0200
Sibylle Koczian wrote:
> Am 15.08.2020 um 10:14 schrieb Manfred Lotz:
> > Hi Chris,
> > Thanks a lot for you advice.
> >
> > On Sat, 15 Aug 2020 16:15:29 +1000
> > Chris Angelico wrote:
> >
> >> On Sat, Aug 15, 2020 at 3:36 PM Manfred Lotz
> >> wrote:
> >>
Am 15.08.2020 um 10:14 schrieb Manfred Lotz:
Hi Chris,
Thanks a lot for you advice.
On Sat, 15 Aug 2020 16:15:29 +1000
Chris Angelico wrote:
On Sat, Aug 15, 2020 at 3:36 PM Manfred Lotz
wrote:
I have an object which I could initialize providind an int or a str.
...
For my use case I do
.
> >>
> >> I am not sure which of the following is best to use
> >> - try/except
> >> - if type(int)...
> >> - if isinstance(v, int)
> >>
> >> Here a minimal example
> >>
> >> def get_id(fromname):
> >&g
f the following is best to use
> > - try/except
> > - if type(int)...
> > - if isinstance(v, int)
> >
> > Here a minimal example
> >
> > def get_id(fromname):
> > # do something with `fromname`
> > return 0
> >
> > def get_name
Chris Angelico wrote:
> On Sat, Aug 15, 2020 at 3:36 PM Manfred Lotz wrote:
>>
>> I have an object which I could initialize providind an int or a str.
>>
>> I am not sure which of the following is best to use
>> - try/except
>> - if type(int)...
>>
On Sat, Aug 15, 2020 at 3:36 PM Manfred Lotz wrote:
>
> I have an object which I could initialize providind an int or a str.
>
> I am not sure which of the following is best to use
> - try/except
> - if type(int)...
> - if isinstance(v, int)
>
> Here a minimal exam
I have an object which I could initialize providind an int or a str.
I am not sure which of the following is best to use
- try/except
- if type(int)...
- if isinstance(v, int)
Here a minimal example
def get_id(fromname):
# do something with `fromname`
return 0
def get_name(fromid
On Thu, 22 Sep 2016 11:40 pm, Sayth Renshaw wrote:
> True it failed, just actually happy to get it to fail or pass successfully
> on int input.
But it doesn't. It raises ValueError no matter what you enter.
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
e
in
trying to get this to work.
Half opt for try except the other half if else and then implement them largely
differently. Every many and varied approach str2bool(), isalpha() using list
with isinstance(var, [ int, str, bool]) etc.
Anyway back to the old drawing board.
Cheers
Sayth
IMHO
e input() returns a string in Python 3, this will always be a string.
>
>
> > if isinstance(int(answer), int) is True:
>
> int(answer) will either succeed, or it will fail. If it fails, it will raise
> ValueError, and your code will fail with an exception.
>
> If it su
On Wednesday, September 21, 2016 at 11:41:42 PM UTC-4, Sayth Renshaw wrote:
answer = input("\t >> ")
if isinstance(int(answer), int) is True:
raise ValueError("Ints aren't valid input")
You seem to be trying to check that the user hasn't entered
an in
s will always be a string.
> if isinstance(int(answer), int) is True:
int(answer) will either succeed, or it will fail. If it fails, it will raise
ValueError, and your code will fail with an exception.
If it succeeds, then it will return an int. Testing whether int(answer)
returns an int is a
On Wednesday, September 21, 2016 at 11:41:42 PM UTC-4, Sayth Renshaw wrote:
> This ends being the code I can use to get it to work, seems clear and
> pythonic, open to opinion on that :-)
>
>
> answer = input("\t >> ")
> if isinstance(int(answer), int) is
On Thursday, September 22, 2016 at 3:41:42 PM UTC+12, Sayth Renshaw wrote:
> if isinstance(int(answer), int) is True:
Not sure what the point of this is...
--
https://mail.python.org/mailman/listinfo/python-list
This ends being the code I can use to get it to work, seems clear and pythonic,
open to opinion on that :-)
answer = input("\t >> ")
if isinstance(int(answer), int) is True:
raise ValueError("Ints aren't valid input")
sys.exit()
elif isinstance(answer, str
none-true-or-false
___
I actually thought this would have resolved my issues and still returned error
if ints entered however it still passes through.
answer = input("\t >> ")
if isinstance(answer, str) is True:
prin
ou can't str () and get a
> valuerror you use conditional logic with strings.
What sort of conditional logic do you think you will use to determine
whether or not str(x) will fail?
> Therefore to try and keep with pythons only one obvious way of doing
> things should i prefer condi
In Sayth Renshaw
writes:
> Trying to clarify why ints and strings arent treated the same.
Because they are not the same.
> You can get a valuerror from trying to cast a non-int to an int as in
> int(3.0) however you cannot do a non string with str(a).
Anything you type can be represented as
vious way of doing things
> should i prefer conditional logic for all using isinstance?
>
> That way regardless of input type my code flows the same and more explicitly
> states the intended type.
> Sayth
How you do your check depends a lot on why you are checking, how strange a
value y
valuerror.
However as you can't str () and get a valuerror you use conditional logic with
strings.
Therefore to try and keep with pythons only one obvious way of doing things
should i prefer conditional logic for all using isinstance?
That way regardless of input type my code flows the same and
t;>> 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 __instan
r 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?
>>
>> Yes -- see Terry Reedy
ent the post prematurely. Meant to say:
>>
>> Or is there a magic __instancecheck__ method somewhere that I'm not aware
>> of?
>
> Yes -- see Terry Reedy's post.
>
> isinstance(inst, klass) ends up calling
>
> type(klass).__instancecheck__(klass, inst)
I
od somewhere that I'm not aware
> of?
Yes -- see Terry Reedy's post.
isinstance(inst, klass) ends up calling
type(klass).__instancecheck__(klass, inst)
--
Steven
--
https://mail.python.org/mailman/listinfo/python-list
quot;,bitfield.c_uint,2),))
>>>> bf
>
>>>> bf.__mro__
> (, , '_ctypes._CData'>, , )
>>>> type(bf)
>
>>>> type(bf).__mro__
> (, , )
>
> If that's the case, then it's quite correct: bf is not a Bitfield, it is
> a su
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 s
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.__insta
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) ---
In [649]: bf.__mro__
Out[649]
ted right above it. It
was, apparently, the recommended way to do this in python up to 1.4,
before isinstance existed.
It only worked with [old-style, goes without saying] instance and class
objects and not, say, ints, but AFAICT isinstance in 1.5 didn't support
anything else either. Since t
On 8/25/2015 10:32 AM, random...@fastmail.us wrote:
On Mon, Aug 24, 2015, at 22:12, Andrew Wang wrote:
[question snipped]
And, now, your moment of zen:
Huh?? I fail to see the point of this buggy code.
def isa(ob, cl):
try:
raise ob
except cl:
return 1
else: return
answer in 2006, since we didn't have either Python 3 or abstract
classes back then.
The IsInstance (and IsSubclass) function documentation mentions that
they use the methods __instancecheck__ [and __subclasscheck__],
presumably to support abstract classes.
The actual implementation of
Hi.
I know this thread is ancient, but I would like to know the answer as well (
https://mail.python.org/pipermail/python-list/2006-May/413542.html).
Thanks.
Andrew
--
https://mail.python.org/mailman/listinfo/python-list
On 11/29/2012 9:59 AM, lars van gemerden wrote:
Hi,
I have encountered some strange behavior of isinstance(/issubclass): depending
on the import path used for classes i get different output, while the classes i
compare are in the same file.
Basically if i import a class as:
from mod1
On Thu, Nov 29, 2012 at 9:07 AM, lars van gemerden wrote:
> > PS: this is somewhat simpler than the actual case i've encountered, and
> i haven't tested this exact case, but for now i hope this is enough to get
> some of your insight.
>
> I know for sure that the imports both import the same file,
On Thursday, November 29, 2012 3:59:37 PM UTC+1, lars van gemerden wrote:
> Hi,
>
>
>
> I have encountered some strange behavior of isinstance(/issubclass):
> depending on the import path used for classes i get different output, while
> the classes i compare
On Fri, Nov 30, 2012 at 1:59 AM, lars van gemerden wrote:
> Basically if i import a class as:
>
> from mod1.mod2 import A
>
> or:
>
> from mod0.mod1.mod2 import A
>
> which both result in importing the same class, a call to isinstance(inst, A)
> in anoth
Hi,
I have encountered some strange behavior of isinstance(/issubclass): depending
on the import path used for classes i get different output, while the classes i
compare are in the same file.
Basically if i import a class as:
from mod1.mod2 import A
or:
from mod0.mod1.mod2 import
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
>
file. In Python 2, I used "isinstance(p, file)" to
> determine whether the parameter p is a file. In Python 3, the
> returnvalue of open() is of type _io.TextIOWrapper, while the built-in
> class file doesn't exist, so I can't use that code.
>
> Secondly, c
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 de
hon 2, I used "isinstance(p, file)" to
determine whether the parameter p is a file. In Python 3, the
returnvalue of open() is of type _io.TextIOWrapper, while the built-in
class file doesn't exist, so I can't use that code.
Secondly, checking for the type is kind-of ugly, beca
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 "isinstance(p,
On Mon, Jul 4, 2011 at 12:53 PM, MRAB wrote:
> On 04/07/2011 20:41, Amaury Forgeot d'Arc wrote:
>>> Le lundi 04 juillet 2011 à 10:52 -0700, Gregory P. Smith a écrit :
note that a fast lookup implies exact type and not subclass making my
point silly... at which point you're back to i
On 04/07/2011 20:41, Amaury Forgeot d'Arc wrote:
Hi,
2011/7/4 Antoine Pitrou:
Le lundi 04 juillet 2011 à 10:52 -0700, Gregory P. Smith a écrit :
note that a fast lookup implies exact type and not subclass making my
point silly... at which point you're back to iterating so I suspect
supporting
dmitrey wrote:
Yes, you are right. But I have to do it due to another issue I haven't
solved yet: Python3 imports don't see files from same directory
http://groups.google.com/group/comp.lang.python/browse_thread/thread/9470dbdacc138709#
That's because the syntax for relative imports has ch
On May 7, 11:53 am, Gregory Ewing wrote:
> Chris Rebert wrote:
> > This is because you did `from Point import
> > ...` in file2.py, whereas in file1.py you did `from
> > openopt.kernel.Point import ...`. These 2 different ways of referring
> > to the same module are sufficient to "trick"/"outsmart
Chris Rebert wrote:
This is because you did `from Point import
...` in file2.py, whereas in file1.py you did `from
openopt.kernel.Point import ...`. These 2 different ways of referring
to the same module are sufficient to "trick"/"outsmart" (C)Python and
cause it to import the same module twice
On Fri, May 6, 2011 at 4:20 AM, dmitrey wrote:
> Thanks Cris, however, I had understood reason of the bug and mere
> informed Python developers of the bug to fix it.
No you haven't. Few if any Python developers make a habit of reading
this newsgroup. To actually report the issue so that it migh
ernel.Point import Point
> > p = Point()
>
> > now let's pass p into a func from .../openopt/kernel/file2.py and
> > check
> > from Point import Point
> > isinstance(p, Point)
>
> > So, it returns False!
>
> > p is , while Point is > openopt.kern
p into a func from .../openopt/kernel/file2.py and
> check
> from Point import Point
> isinstance(p, Point)
>
> So, it returns False!
>
> p is , while Point is openopt.kernel.Point.Point at 0x2048e20>
>
> [Subject: seems like a bug in isinstance()]
This is due to a pec
hi all,
suppose I've created a class Point in file .../openopt/kernel/Point.py
Consider the code in file .../somewhere/file1.py
from openopt.kernel.Point import Point
p = Point()
now let's pass p into a func from .../openopt/kernel/file2.py and
check
from Point import Point
isinstanc
Michele Petrazzo wrote:
> Hi all,
> I'm playing with python internals and I'm discovering a strange behavior
> of isinstance. Considering the following test case:
>
> test/bar.py
> test/b.py
> test/a/__init__.py
> test/a/foo.py
>
> -- __init__.py -> e
Hi all,
I'm playing with python internals and I'm discovering a strange behavior
of isinstance. Considering the following test case:
test/bar.py
test/b.py
test/a/__init__.py
test/a/foo.py
-- __init__.py -> empty
--- foo.py:
class foo: pass
c = foo
--- b.py
def ret():
d = {}
>
>>>> import datetime
>
>>>> dt1 = datetime.datetime(2010, 10, 2)
>>>> type(dt1)
>
>>>> isinstance(dt1, datetime.datetime)
> True
>>>> isinstance(dt1, datetime.date)
> True
>
>>>> dt2 = datetime.date(2010, 10, 2)
>
lead to this:
>
>>>> import datetime
>
>>>> dt1 = datetime.datetime(2010, 10, 2)
>>>> type(dt1)
>
>>>> isinstance(dt1, datetime.datetime)
> True
>>>> isinstance(dt1, datetime.date)
> True
>
>>>> dt2 = datetime.d
tetime(2010, 10, 2)
>>> type(dt1)
>>> isinstance(dt1, datetime.datetime)
True
>>> isinstance(dt1, datetime.date)
True
>>> dt2 = datetime.date(2010, 10, 2)
>>> type(dt2)
>>> isinstance(dt2, datetime.datetime)
False
>>> isinstance(dt2, da
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
nt to do so via duck typing. Its rare. But it
is there. That isinstance()/issubclass got a boost in power with the
ABC's and registering, while at the same time the ability to introspect
about the function-y callable-y ness of a function was removed? Makes no
sense to me. But alas!
There&
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
ing, I
>>> too have on occassion wanted to dispatch based on 'is callable? do x'.
>>> Sometimes its not convenient to do so via duck typing. Its rare. But it
>>> is there. That isinstance()/issubclass got a boost in power with the
>>> ABC's and reg
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
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
metimes its not convenient to do so via duck typing. Its rare. But it
is there. That isinstance()/issubclass got a boost in power with the
ABC's and registering, while at the same time the ability to introspect
about the function-y callable-y ness of a function was removed? Makes no
sense to me. But al
ased on 'is callable? do x'.
>> Sometimes its not convenient to do so via duck typing. Its rare. But it
>> is there. That isinstance()/issubclass got a boost in power with the
>> ABC's and registering, while at the same time the ability to introspect
>> about t
nt to do so via duck typing. Its rare. But it
> is there. That isinstance()/issubclass got a boost in power with the
> ABC's and registering, while at the same time the ability to introspect
> about the function-y callable-y ness of a function was removed? Makes no
> sense
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
su
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
>&
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 isins
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
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
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
>
>
>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
>&
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
.
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
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-defin
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)
>&g
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 wa
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
1 - 100 of 245 matches
Mail list logo