Re: if instance exists problem ..

2007-10-22 Thread Mike Orr
On Oct 17, 8:00 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Wed, 17 Oct 2007 23:12:15 +, Paul Hankin wrote: > > 'if x' doesn't test if x exists, it tests if x when cast to a bool is > > True. > > To be pedantic: > > Python doesn't have type casts. bool(x) doesn't cast

Re: if instance exists problem ..

2007-10-18 Thread Diez B. Roggisch
Ben Finney wrote: > "Diez B. Roggisch" <[EMAIL PROTECTED]> writes: > >> stef mientki schrieb: >> > What should I do to the same simple test for existance ? >> >> Use isinstance(obj, type). > > No, that's *far* more specific than "does it exist", and will give > false negatives. I've misread th

Re: if instance exists problem ..

2007-10-17 Thread Gabriel Genellina
En Thu, 18 Oct 2007 00:07:34 -0300, Steven D'Aprano <[EMAIL PROTECTED]> escribió: > On Thu, 18 Oct 2007 03:00:56 +, Steven D'Aprano wrote: > >> On Wed, 17 Oct 2007 23:12:15 +, Paul Hankin wrote: >> >>> 'if x' doesn't test if x exists, it tests if x when cast to a bool is >>> True. >> >>

Re: if instance exists problem ..

2007-10-17 Thread Steven D'Aprano
On Thu, 18 Oct 2007 03:00:56 +, Steven D'Aprano wrote: > On Wed, 17 Oct 2007 23:12:15 +, Paul Hankin wrote: > >> 'if x' doesn't test if x exists, it tests if x when cast to a bool is >> True. > > To be pedantic: > > Python doesn't have type casts. bool(x) doesn't cast x as a bool, it >

Re: if instance exists problem ..

2007-10-17 Thread Steven D'Aprano
On Wed, 17 Oct 2007 23:12:15 +, Paul Hankin wrote: > 'if x' doesn't test if x exists, it tests if x when cast to a bool is > True. To be pedantic: Python doesn't have type casts. bool(x) doesn't cast x as a bool, it creates a brand new Boolean object from x. Also, the "if x" test looks at

Re: if instance exists problem ..

2007-10-17 Thread Ben Finney
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes: > stef mientki schrieb: > > What should I do to the same simple test for existance ? > > Use isinstance(obj, type). No, that's *far* more specific than "does it exist", and will give false negatives. Much better is:: foo = None foo = do_so

Re: if instance exists problem ..

2007-10-17 Thread Diez B. Roggisch
stef mientki schrieb: > hello, > > I've written a convenience wrapper around ConfigObj (which is a imporved > ConfigParser). > > Now if I use an instance of the base class, I can easily test is the > instance exists by " if ini:", > like in this example > >ini = None >if ini: >

Re: if instance exists problem ..

2007-10-17 Thread Paul Hankin
On Oct 17, 11:39 pm, stef mientki <[EMAIL PROTECTED]> wrote: > the test if an instance exists, always returns false. > ini = inifile (filename) > if ini: > print 'ok',type(ini) > else: > print 'wrong',type(ini) > > Why is that ? > What should I do to the same simple test

if instance exists problem ..

2007-10-17 Thread stef mientki
hello, I've written a convenience wrapper around ConfigObj (which is a imporved ConfigParser). Now if I use an instance of the base class, I can easily test is the instance exists by " if ini:", like in this example ini = None if ini: print 'ok',type(ini) else: prin