Re: isinstance(False, int)

2010-03-05 Thread Steven D'Aprano
7;t like it very much. >> >> > So, the pythonic way to check for True/False should be: > >>>> 1 is True > False Why do you need to check for True/False? But if you need to, yes, that is one way. Another would be: isinstance(flag, bool) But generally, you can use any object as a flag without caring if it is actually True or False. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: isinstance(False, int)

2010-03-05 Thread mk
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

Re: isinstance(False, int)

2010-03-05 Thread Rolando Espinoza La Fuente
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

Re: isinstance(False, int)

2010-03-05 Thread Jean-Michel Pichavant
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.

Re: isinstance(False, int)

2010-03-05 Thread mk
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

Re: isinstance(False, int)

2010-03-05 Thread MRAB
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 su

Re: isinstance(False, int)

2010-03-05 Thread Rolando Espinoza La Fuente
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

Re: isinstance(False, int)

2010-03-05 Thread Steven D'Aprano
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 > >

Re: isinstance(False, int)

2010-03-05 Thread Stephen Hansen
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://ww

Re: isinstance(False, int)

2010-03-05 Thread Arnaud Delobelle
mk writes: >>>> isinstance(False, int) > True >>>> >>>> isinstance(True, int) > True > > Huh? > >>>> >>>> issubclass(bool, int) > True > > Huh?! > > Regards, > mk Yes, and: >>> True + Fa

Re: isinstance(False, int)

2010-03-05 Thread Steve Holden
mk wrote: >>>> isinstance(False, int) > True >>>> >>>> isinstance(True, int) > True > > Huh? > >>>> >>>> issubclass(bool, int) > True > > Huh?! > >>> 3+True 4 >>> 3+False 3 >>> J

isinstance(False, int)

2010-03-05 Thread mk
>>> isinstance(False, int) True >>> >>> isinstance(True, int) True Huh? >>> >>> issubclass(bool, int) True Huh?! Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Re: isinstance(obj, type(obj)) == True?

2009-06-24 Thread Terry Reedy
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)

Re: isinstance(obj, type(obj)) == True?

2009-06-24 Thread Chris Rebert
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

isinstance(obj, type(obj)) == True?

2009-06-24 Thread Art
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 occurs after 'reload'ing the file in the interp

Re: something wrong with isinstance

2009-02-13 Thread Terry Reedy
Gabriel Genellina wrote: En Fri, 13 Feb 2009 08:43:03 -0200, Peter Otten <__pete...@web.de> escribió: class Type(type): ... def __instancecheck__(self, other): return True ... class A(metaclass=Type): pass ... class B: pass ... isinstance(B(), A) True See also

Re: something wrong with isinstance

2009-02-13 Thread Gabriel Genellina
En Fri, 13 Feb 2009 08:43:03 -0200, Peter Otten <__pete...@web.de> escribió: Gabriel Genellina wrote: En Fri, 13 Feb 2009 08:07:58 -0200, Carl Banks escribió: But that brings up another very slight possibility, though not a very likely one in this case: the behavior of isinstance

Re: something wrong with isinstance

2009-02-13 Thread Peter Otten
; likely one in this case: the behavior of isinstance can be >> customized. It can happen unbeknownst to a user who subclasses a >> class that does that. > > Really? I didn't know that -- how do you do that? >>> class Type(type): ... def __instance

Re: something wrong with isinstance

2009-02-13 Thread Gabriel Genellina
En Fri, 13 Feb 2009 08:07:58 -0200, Carl Banks escribió: Well, the OP said he was using Python 3.0, where all classes are new- style classes. But that brings up another very slight possibility, though not a very likely one in this case: the behavior of isinstance can be customized. It can

Re: something wrong with isinstance

2009-02-13 Thread Carl Banks
ity, though not a very likely one in this case: the behavior of isinstance can be customized. It can happen unbeknownst to a user who subclasses a class that does that. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: something wrong with isinstance

2009-02-13 Thread Bruno Desthuilliers
maksym.ka...@gmail.com a écrit : Hi there. now i'm a complete newbie for python, and maybe my problem is stupid but i cannot solve it myself Others already addressed your problem (cf Paul and Diez answers). I'll just allow myself to point a couple other potential problems with your code: #

Re: something wrong with isinstance

2009-02-13 Thread Bruno Desthuilliers
redbaron a écrit : Don't really sure, but try to define your class as new-style one. isinstance() works as well with classic classes. -- http://mail.python.org/mailman/listinfo/python-list

Re: something wrong with isinstance

2009-02-12 Thread Diez B. Roggisch
(self, obj): if isinstance(obj, GeoMap): return None return json.JSONEncoder.default(self, obj) def main(): print(json.dumps(2 + 5j, cls=ComplexEncoder)) geomap = testdata.createTestMap() print(json.dumps(geomap, cls=GeoMapEncoder)) pass if __n

Re: something wrong with isinstance

2009-02-12 Thread Paul McGuire
On Feb 12, 12:26 pm, maksym.ka...@gmail.com wrote: > > Well the output of > > > print(type(obj)) > > print(str(obj)) > > was > > > > > Just looks well, isn't it? i have no idea what's wrong So then how do you know isinstance is evaluating

Re: something wrong with isinstance

2009-02-12 Thread maksym . kaban
On 12 фев, 21:49, redbaron wrote: > Don't really sure, but try to define your class as new-style one. > Like > class GeoMap(object): >    ... Sorry, it didn't work -- http://mail.python.org/mailman/listinfo/python-list

Re: something wrong with isinstance

2009-02-12 Thread redbaron
Don't really sure, but try to define your class as new-style one. Like class GeoMap(object): ... -- http://mail.python.org/mailman/listinfo/python-list

Re: something wrong with isinstance

2009-02-12 Thread maksym . kaban
> Here's a crazy idea out of left field.  Just before calling > isinstance, why not try: > > print(type(obj)) > print(str(obj)) > > This may illuminate the unexpected behavior, you'll find out just what > obj has in it. > > -- Paul Well the output of &

Re: something wrong with isinstance

2009-02-12 Thread Paul McGuire
t; > import testdata > import json > > class GeoMapEncoder(json.JSONEncoder): >     def default(self, obj): >         if isinstance(obj, GeoMap): >             return None >         return json.JSONEncoder.default(self, obj) > > def main(): >     print(json.dumps(2 + 5

something wrong with isinstance

2009-02-12 Thread maksym . kaban
ts to json notation. So i imported json module and as shown in docs for it extended JSONEncoder class. Look at the code below ##main module from worldmap import GeoMap, GeoMapCell import testdata import json class GeoMapEncoder(json.JSONEncoder): def default(self, obj): if isinstanc

Re: Python 3 isinstance

2009-01-16 Thread Duncan Booth
Steven D'Aprano wrote: > On Fri, 16 Jan 2009 09:58:53 +, Duncan Booth wrote: > >> That still leaves the question whether anyone has ever actually taken >> advantage of this feature. You can do isinstance(x, (IntType, >> LongType, StringTypes)) but I didn

Re: Python 3 isinstance

2009-01-16 Thread Steven D'Aprano
On Fri, 16 Jan 2009 09:58:53 +, Duncan Booth wrote: > That still leaves the question whether anyone has ever actually taken > advantage of this feature. You can do isinstance(x, (IntType, LongType, > StringTypes)) but I didn't even know that StringTypes existed until a > coup

Re: Python 3 isinstance

2009-01-16 Thread Duncan Booth
Carl Banks wrote: > On Jan 15, 1:08 pm, Duncan Booth wrote: >> Carl Banks wrote: >> > I don't see what the big deal is.  Right now isinstance accepts a >> > typ > e >> > or a tuple of types.  The code could be changed to allow a type, or >&g

Re: Python 3 isinstance

2009-01-15 Thread Rhamphoryncus
On Jan 14, 3:14 pm, "Lambert, David W (S&T)" wrote: > Please, why isn't a set permitted as the second argument to isinstance? The real problem is it would be misleading. isinstance(a, myset) suggests implementation like type(a) in myset, but it's really any (isin

Re: Python 3 isinstance

2009-01-15 Thread Carl Banks
On Jan 15, 1:08 pm, Duncan Booth wrote: > Carl Banks wrote: > > I don't see what the big deal is.  Right now isinstance accepts a type > > or a tuple of types.  The code could be changed to allow a type, or > > any iterable the returns types (wherein every items of th

Re: Python 3 isinstance

2009-01-15 Thread John Machin
On Jan 16, 4:28 am, "Lambert, David W (S&T)" wrote: > Although isinstance predates sets, the python history I recall is that > allowing tuples as second argument to isinstance happened at about the > same time as set type was builtin. isinstance 2nd arg as tuple of typ

Re: Python 3 isinstance

2009-01-15 Thread Terry Reedy
Duncan Booth wrote: Terry Reedy wrote: Lambert, David W (S&T) wrote: Overly terse. I do mean that this is illegal: isinstance(s, {str, bytes}) tuples have order, immutability, and the possibility of repeat items. A set is most reasonable in a mathematical sense. I agree. How

Re: Python 3 isinstance

2009-01-15 Thread Duncan Booth
Carl Banks wrote: > I don't see what the big deal is. Right now isinstance accepts a type > or a tuple of types. The code could be changed to allow a type, or > any iterable the returns types (wherein every items of the sequence is > required to be a type). What's mes

Re: Python 3 isinstance

2009-01-15 Thread Carl Banks
On Jan 15, 3:35 am, Duncan Booth wrote: > Terry Reedy wrote: > > Lambert, David W (S&T) wrote: > >> Overly terse.  I do mean that this is illegal: > > >> isinstance(s, {str, bytes}) > > >> tuples have order, immutability, and the possibility of repe

Re: Python 3 isinstance

2009-01-15 Thread
Although isinstance predates sets, the python history I recall is that allowing tuples as second argument to isinstance happened at about the same time as set type was builtin. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3 isinstance

2009-01-15 Thread MRAB
split() > > instead of > > __all__ = 'this','that','imTiredOfMistypingCommasAndQuotes' > > > if not isinstance(o,set_of_handled_types): > raise TypeError('call blessed programmer, this cannot occur') > if isinstance(o,set_of_handle_types-treat_differently): &g

Re: Python 3 isinstance

2009-01-15 Thread
I have use case, needn't be dynamic, and it's not hard to enclose set as tuple. But I also write (for example) __all__ = 'this that other'.split() string_list = 'evenOneWord'.split() instead of __all__ = 'this','that','i

Re: Python 3 isinstance

2009-01-15 Thread MRAB
Lambert, David W (S&T) wrote: Overly terse. I do mean that this is illegal: isinstance(s, {str, bytes}) tuples have order, immutability, and the possibility of repeat items. A set is most reasonable in a mathematical sense. You could say the same about s.startswith(("a", &q

Re: Python 3 isinstance

2009-01-15 Thread Duncan Booth
Terry Reedy wrote: > Lambert, David W (S&T) wrote: >> Overly terse. I do mean that this is illegal: >> >> isinstance(s, {str, bytes}) >> >> tuples have order, immutability, and the possibility of repeat items. >> >> A set is most reasonabl

Re: Python 3 isinstance

2009-01-14 Thread Steven D'Aprano
On Wed, 14 Jan 2009 22:03:37 -0500, Lambert, David W (S&T) wrote: > Overly terse. I do mean that this is illegal: > > isinstance(s, {str, bytes}) *shrug* Just change the {} to () and it will work fine. Or do this: isinstance(s, tuple({str, bytes})) > tuples have order, i

Re: Python 3 isinstance

2009-01-14 Thread Terry Reedy
Lambert, David W (S&T) wrote: Overly terse. I do mean that this is illegal: isinstance(s, {str, bytes}) tuples have order, immutability, and the possibility of repeat items. A set is most reasonable in a mathematical sense. I agree. However, isinstance predates set. Hence the status

Re: Python 3 isinstance

2009-01-14 Thread John Machin
On Jan 15, 2:03 pm, "Lambert, David W (S&T)" wrote: > Overly terse. I do mean that this is illegal: > > isinstance(s, {str, bytes}) > > tuples have order, immutability, and the possibility of repeat items. In the anticipated/usual use case (the type/class names a

Re: Python 3 isinstance

2009-01-14 Thread James Mills
On Thu, Jan 15, 2009 at 1:03 PM, Lambert, David W (S&T) wrote: > Overly terse. I do mean that this is illegal: > > isinstance(s, {str, bytes}) > > tuples have order, immutability, and the possibility of repeat items. > > A set is most reasonable in a mathematical

Re: Python 3 isinstance

2009-01-14 Thread
Overly terse. I do mean that this is illegal: isinstance(s, {str, bytes}) tuples have order, immutability, and the possibility of repeat items. A set is most reasonable in a mathematical sense. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3 isinstance

2009-01-14 Thread Carl Banks
On Jan 14, 4:14 pm, "Lambert, David W (S&T)" wrote: > Please, why isn't a set permitted as the second argument to isinstance? The Python development team might be open to adding it if you were to submit a patch. The use case is fairly obvious. I doubt any of them would

Re: Python 3 isinstance

2009-01-14 Thread MRAB
Lambert, David W (S&T) wrote: Please, why isn't a set permitted as the second argument to isinstance? Do you mean set as a class ("isinstance(s, set)", which is valid) or a set of classes ("isinstance(s, set([str, bytes])", which isn't valid)? -- http://mail.

Re: Python 3 isinstance

2009-01-14 Thread James Mills
On Thu, Jan 15, 2009 at 8:14 AM, Lambert, David W (S&T) wrote: > Please, why isn't a set permitted as the second argument to isinstance? Care to show us a code sample ? We're not psychic you know... cheers James -- http://mail.python.org/mailman/listinfo/python-list

Python 3 isinstance

2009-01-14 Thread
Please, why isn't a set permitted as the second argument to isinstance? -- http://mail.python.org/mailman/listinfo/python-list

Re: ABCs -> infix syntax for isinstance() ?

2008-10-09 Thread Boris Borcic
Terry Reedy wrote: Boris Borcic wrote: ... - allowing containment tests, ie "x in Number" to invoke isinstance() in the background when the container is of type . My brain is too muddled by flu at the moment, to see whether Guido's fabled time machine allowed him to already

Re: ABCs -> infix syntax for isinstance() ?

2008-10-08 Thread Boris Borcic
Bruno Desthuilliers wrote: [EMAIL PROTECTED] a écrit : ... A intriguing wider proposition would be to transpose Ruby's notion of "Open Classes" to Python built-in metaclasses (or just to type itself ?). No, thanks. Even the Ruby guys start to think making evrything open may not be such a goo

Re: ABCs -> infix syntax for isinstance() ?

2008-10-07 Thread Bruno Desthuilliers
Boris Borcic a écrit : Bruno Desthuilliers wrote: Boris Borcic a écrit : Given the ABC innovation, maybe an infix syntax for isinstance() would be good. Possibilities : - stealing "is" away from object identity. As a motivation, true use cases for testing object identity are rare

Re: ABCs -> infix syntax for isinstance() ?

2008-10-07 Thread Boris Borcic
Bruno Desthuilliers wrote: Boris Borcic a écrit : Given the ABC innovation, maybe an infix syntax for isinstance() would be good. Possibilities : - stealing "is" away from object identity. As a motivation, true use cases for testing object identity are rare; "x is None"

Re: ABCs -> infix syntax for isinstance() ?

2008-10-06 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Bruno Desthuilliers dixit : Boris Borcic a écrit : Given the ABC innovation, maybe an infix syntax for isinstance() would be good. Possibilities : - stealing "is" away from object identity. As a motivation, true use cases for testing object identity are

Re: ABCs -> infix syntax for isinstance() ?

2008-10-05 Thread bborcic
Bruno Desthuilliers dixit : > Boris Borcic a écrit : > > > Given the ABC innovation, maybe an infix syntax for isinstance() would > > be good. > > > Possibilities : > > > - stealing "is" away from object identity. As a motivation, true use > > c

Re: ABCs -> infix syntax for isinstance() ?

2008-10-03 Thread Terry Reedy
Boris Borcic wrote: Given the ABC innovation, maybe an infix syntax for isinstance() would be good. Possibilities : - stealing "is" away from object identity. As a motivation, true use cases for testing object identity are rare; forcing the usage of a function or method to test

Re: ABCs -> infix syntax for isinstance() ?

2008-10-03 Thread Bruno Desthuilliers
Boris Borcic a écrit : Given the ABC innovation, maybe an infix syntax for isinstance() would be good. Possibilities : - stealing "is" away from object identity. As a motivation, true use cases for testing object identity are rare; "x is None" is a *very* common t

Re: ABCs -> infix syntax for isinstance() ?

2008-10-03 Thread bearophileHUGS
Boris Borcic: > - combining both keywords to create a third one, eg "is in" A note only on syntax: "isa" seems better for Python. I don't comment how useful it can be. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

ABCs -> infix syntax for isinstance() ?

2008-10-03 Thread Boris Borcic
Given the ABC innovation, maybe an infix syntax for isinstance() would be good. Possibilities : - stealing "is" away from object identity. As a motivation, true use cases for testing object identity are rare; forcing the usage of a function or method to test it, would diss

Re: reloading modules and isinstance()

2007-12-14 Thread Diez B. Roggisch
Tlis schrieb: > Hi, > > I have found that it is possible to reassign the instance.__class__ > reference to the same class (but after reloading) to make the > isinstance() test work again! I know that it is a kind of hacking of > the Python interpreter, but it works :-) I

Re: reloading modules and isinstance()

2007-12-14 Thread Tlis
Hi, I have found that it is possible to reassign the instance.__class__ reference to the same class (but after reloading) to make the isinstance() test work again! I know that it is a kind of hacking of the Python interpreter, but it works :-) -- http://mail.python.org/mailman/listinfo/python

Re: reloading modules and isinstance()

2007-12-06 Thread Jean-Paul Calderone
On Thu, 06 Dec 2007 13:59:00 +0100, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > [snip] >> >> Who says it isn't feasible? >> >> http://twistedmatrix.com/trac/browser/trunk/twisted/python/rebuild.py > >Nice try - for sure. But it seems to be geared towards special cases, >not a general-purpose "

Re: reloading modules and isinstance()

2007-12-06 Thread Diez B. Roggisch
Jean-Paul Calderone schrieb: > On Thu, 06 Dec 2007 12:21:01 +0100, "Diez B. Roggisch" > <[EMAIL PROTECTED]> wrote: >> Tlis schrieb: >>> On 5 Dec, 13:18, Steven D'Aprano <[EMAIL PROTECTED] >>> cybersource.com.au> wrote: On Tue, 04 Dec 2007 15:41:48 +0100, Diez B. Roggisch wrote: > You just

Re: reloading modules and isinstance()

2007-12-06 Thread Jean-Paul Calderone
On Thu, 06 Dec 2007 12:21:01 +0100, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >Tlis schrieb: >> On 5 Dec, 13:18, Steven D'Aprano <[EMAIL PROTECTED] >> cybersource.com.au> wrote: >>> On Tue, 04 Dec 2007 15:41:48 +0100, Diez B. Roggisch wrote: You just discovered one reason why reload() is

Re: reloading modules and isinstance()

2007-12-06 Thread Diez B. Roggisch
Tlis schrieb: > On 5 Dec, 13:18, Steven D'Aprano <[EMAIL PROTECTED] > cybersource.com.au> wrote: >> On Tue, 04 Dec 2007 15:41:48 +0100, Diez B. Roggisch wrote: >>> You just discovered one reason why reload() is a bad idea and IMHO >>> shouldn't be used at all - as tempting it might be. >> I disagre

Re: reloading modules and isinstance()

2007-12-05 Thread Gabriel Genellina
En Wed, 05 Dec 2007 15:06:43 -0300, Tlis <[EMAIL PROTECTED]> escribi�: > With all the problems of the reload() function, I still hope, that > there should be possible to write a safe module 'reloader', that would > fix the references, as required (e.g. by changing the > variable.__class__ referenc

Re: reloading modules and isinstance()

2007-12-05 Thread Chris Mellon
On Dec 5, 2007 12:06 PM, Tlis <[EMAIL PROTECTED]> wrote: > On 5 Dec, 13:18, Steven D'Aprano <[EMAIL PROTECTED] > cybersource.com.au> wrote: > > On Tue, 04 Dec 2007 15:41:48 +0100, Diez B. Roggisch wrote: > > > You just discovered one reason why reload() is a bad idea and IMHO > > > shouldn't be use

Re: reloading modules and isinstance()

2007-12-05 Thread Tlis
On 5 Dec, 13:18, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Tue, 04 Dec 2007 15:41:48 +0100, Diez B. Roggisch wrote: > > You just discovered one reason why reload() is a bad idea and IMHO > > shouldn't be used at all - as tempting it might be. > > I disagree -- I find reload

Re: reloading modules and isinstance()

2007-12-05 Thread Diez B. Roggisch
Steven D'Aprano wrote: > On Tue, 04 Dec 2007 15:41:48 +0100, Diez B. Roggisch wrote: > >> You just discovered one reason why reload() is a bad idea and IMHO >> shouldn't be used at all - as tempting it might be. > > > I disagree -- I find reload() extremely useful for interactively testing > mo

Re: reloading modules and isinstance()

2007-12-05 Thread Steven D'Aprano
On Tue, 04 Dec 2007 15:41:48 +0100, Diez B. Roggisch wrote: > You just discovered one reason why reload() is a bad idea and IMHO > shouldn't be used at all - as tempting it might be. I disagree -- I find reload() extremely useful for interactively testing modules. But I would never dream of usi

Re: reloading modules and isinstance()

2007-12-04 Thread Diez B. Roggisch
Tlis wrote: > I am using a software system with an embedded Python interpreter > (version 2.3) for scripting. The KcsPoint2D.py module contains a > Point2D class with the following method: > > def SetFromMidpoint(self, p1, p2): > if not isinstance(p1, Point2D) or not isin

reloading modules and isinstance()

2007-12-04 Thread Tlis
I am using a software system with an embedded Python interpreter (version 2.3) for scripting. The KcsPoint2D.py module contains a Point2D class with the following method: def SetFromMidpoint(self, p1, p2): if not isinstance(p1, Point2D) or not isinstance(p2, Point2D): raise TypeError

Re: Thoughts on using isinstance

2007-01-26 Thread Terry Hancock
for functionality (e.g. presence of necessary methods) rather than specific inheritence. Using "isinstance" is one of those practices that can really help in quick testbed code or in a prototype, but you usually want to take it out later. Cheers, Terry -- Terry Hancock ([EMAIL PROTECT

Re: Thoughts on using isinstance

2007-01-26 Thread Bruno Desthuilliers
Matthew Woodcraft a écrit : > Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >> Matthew Woodcraft a écrit : > >>> Adding the validation code can make your code more readable, in that >>> it can be clearer to the readers what kind of values are being >>> handled. > >> This is better expressed in

Re: Thoughts on using isinstance

2007-01-25 Thread Matthew Woodcraft
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Matthew Woodcraft a écrit : >> Adding the validation code can make your code more readable, in that >> it can be clearer to the readers what kind of values are being >> handled. > This is better expressed in the docstring. And if it's in the > doc

Re: Thoughts on using isinstance

2007-01-24 Thread Bruno Desthuilliers
abcd a écrit : > Well my example function was simply taking a string and printing, but > most of my cases would be expecting a list, dictionary or some other > custom object. Still propose not to validate the type of data being > passed in? Yes - unless you have a *very* compelling reason to do o

Re: Thoughts on using isinstance

2007-01-24 Thread Bruno Desthuilliers
Matthew Woodcraft a écrit : > abcd <[EMAIL PROTECTED]> wrote: > >>Well my example function was simply taking a string and printing, but >>most of my cases would be expecting a list, dictionary or some other >>custom object. Still propose not to validate the type of data being >>passed in? > > >

Re: Thoughts on using isinstance

2007-01-24 Thread Matthew Woodcraft
abcd <[EMAIL PROTECTED]> wrote: > Well my example function was simply taking a string and printing, but > most of my cases would be expecting a list, dictionary or some other > custom object. Still propose not to validate the type of data being > passed in? There are many people here who will in

Re: Thoughts on using isinstance

2007-01-24 Thread Duncan Booth
Gabriel Genellina <[EMAIL PROTECTED]> wrote: > In > the example above, you can validate that fileobject has a write > attribute: getattr(fileobject, "write"). But I'd only do that if I > have a good reason (perhaps if the file is used after some lengthy > calculation,and I want to be sure that

Re: Thoughts on using isinstance

2007-01-24 Thread Gabriel Genellina
At Wednesday 24/1/2007 14:21, abcd wrote: >Yes because usually you don't expect a list or dictionary but some object > that *acts* like a list or dictionary. Or you even expect just some > aspects of the type's behavior. For example that it is something you can > iterate over. > > Ciao, >

Re: Thoughts on using isinstance

2007-01-24 Thread Diez B. Roggisch
e with another type assumption. The only thing one often checks is for basestring, as basestring supports iteration, but more than often isn't supposed to be iterated over. Small example to gather all strings out of a tree of objects (untested): def foo(arg): # string case if isinsta

Re: Thoughts on using isinstance

2007-01-24 Thread abcd
>Yes because usually you don't expect a list or dictionary but some object > that *acts* like a list or dictionary. Or you even expect just some > aspects of the type's behavior. For example that it is something you can > iterate over. > > Ciao, > Marc 'BlackJack' Rintsch good point. is

Re: Thoughts on using isinstance

2007-01-24 Thread abcd
Well my example function was simply taking a string and printing, but most of my cases would be expecting a list, dictionary or some other custom object. Still propose not to validate the type of data being passed in? Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Thoughts on using isinstance

2007-01-24 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, abcd wrote: > Well my example function was simply taking a string and printing, but > most of my cases would be expecting a list, dictionary or some other > custom object. Still propose not to validate the type of data being > passed in? Yes because usually you don't expe

Re: Thoughts on using isinstance

2007-01-24 Thread abcd
Well my example function was simply taking a string and printing, but most of my cases would be expecting a list, dictionary or some other custom object. Still propose not to validate the type of data being passed in? Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Thoughts on using isinstance

2007-01-24 Thread Steve Holden
abcd wrote: >> The "Python way" is to validate by performing the operations you need to >> perform and catching any exceptions that result. In the case of your >> example, you seem to be saying that you'd rather raise your own >> exception (which, by the way, should really be a subclass of Exceptio

Re: Thoughts on using isinstance

2007-01-24 Thread Bruno Desthuilliers
abcd a écrit : > In my code I am debating whether or not to validate the types of data > being passed to my functions. For example > > def sayHello(self, name): > if not name: > rasie "name can't be null" > if not isinstance(name, str): &g

Re: Thoughts on using isinstance

2007-01-24 Thread Neil Cerutti
On 2007-01-24, abcd <[EMAIL PROTECTED]> wrote: > In my code I am debating whether or not to validate the types of data > being passed to my functions. For example > > def sayHello(self, name): > if not name: > rasie "name can't be null&

Re: Thoughts on using isinstance

2007-01-24 Thread abcd
> The "Python way" is to validate by performing the operations you need to > perform and catching any exceptions that result. In the case of your > example, you seem to be saying that you'd rather raise your own > exception (which, by the way, should really be a subclass of Exception, > but we will

Re: Thoughts on using isinstance

2007-01-24 Thread Duncan Booth
"abcd" <[EMAIL PROTECTED]> wrote: > In my code I am debating whether or not to validate the types of data > being passed to my functions. For example > > def sayHello(self, name): > if not name: > rasie "name can't be null" >

Re: Thoughts on using isinstance

2007-01-24 Thread Steve Holden
abcd wrote: > In my code I am debating whether or not to validate the types of data > being passed to my functions. For example > > def sayHello(self, name): > if not name: > rasie "name can't be null" > if not isinstance(name, str): &g

Re: Thoughts on using isinstance

2007-01-24 Thread Maxim Sloyko
On Jan 24, 3:38 pm, "abcd" <[EMAIL PROTECTED]> wrote: > In my code I am debating whether or not to validate the types of data > being passed to my functions. For example > > def sayHello(self, name): > if not name: > rasie "name can'

Thoughts on using isinstance

2007-01-24 Thread abcd
In my code I am debating whether or not to validate the types of data being passed to my functions. For example def sayHello(self, name): if not name: rasie "name can't be null" if not isinstance(name, str): raise "name must be a string" prin

Re: where are isinstance types documented?

2006-09-26 Thread John Machin
Georg Brandl wrote: > Fredrik Lundh wrote: > > Sion Arrowsmith wrote: > >> > > > >>> based on http://docs.python.org/ref/types.html, here's a list of the > >>> most commonly used core types: > >>> [ ... ] > >>> Sequences: > >>> str > >>> unicode > >>> tuple > >>> list > >> > >> And

Re: where are isinstance types documented?

2006-09-26 Thread Georg Brandl
Fredrik Lundh wrote: > Sion Arrowsmith wrote: >> > >>> based on http://docs.python.org/ref/types.html, here's a list of the >>> most commonly used core types: >>> [ ... ] >>> Sequences: >>> str >>> unicode >>> tuple >>> list >> >> And set, presumably. > > absolutely! > > howeve

Re: where are isinstance types documented?

2006-09-26 Thread Fredrik Lundh
Sion Arrowsmith wrote: > >> based on http://docs.python.org/ref/types.html, here's a list of the >> most commonly used core types: >> [ ... ] >> Sequences: >> str >> unicode >> tuple >> list > > And set, presumably. absolutely! however, sets don't seem to be mentioned on that p

Re: where are isinstance types documented?

2006-09-26 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote: >based on http://docs.python.org/ref/types.html, here's a list of the >most commonly used core types: > [ ... ] >Sequences: > str > unicode > tuple > list And set, presumably. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/

<    1   2   3   >