[DB-SIG] dbiDate - help urgently needed

Chris Cogdon chris at cogdon.org
Mon Jun 2 16:44:34 EDT 2003


On Monday, Jun 2, 2003, at 15:22 US/Pacific, Jeff Sacksteder wrote:

>> Do print `type(known_dbiDate_object)`, and that will print enough 
>> information to figure out what type it actually is. If you're having 
>> difficulty with type and isinstance, then there's a good chance 
>> you're not really looking at dbiDate objects.
>
>
> for item in my_list:
>    print type(item)
>
> returns the following-
>
> <type 'float'>
> <type 'string'>
> <type 'DbiDate'>
>
> I want to do something like-
>
> for item in my_list:
>    if type(item) is StringType:
>       print 'Foo'
>    elif type(item) is DbiDate:
>       print 'Bar'
>    else:
>       print 'Baz'
>
> But DbiDate is an object, not a type. I thought is instance might be 
> the ticket, since it can compare classes _and_ types. No luck so far. 
> Apparently I am the first person in the history of DBI to want to do 
> this.

I'm REALLY surprised that doing a type() on an instance of DbiDate is 
returning <type 'DbiDate'>.

If DbiDate is a 'classic class', then it should return <type 'instance'>
If DbiDate is a 'new class', then it should return something like 
<class '__main__.DbiDate'>

In either case, isinstance should return something sensible. Ie, 
isinstance( item, DbiDate ) should return '1' as appropriate, but 
'type' may not work as expected.

What output are you getting for the second 'for' loop?


-- 
    ("`-/")_.-'"``-._        Chris Cogdon <chris at cogdon.org>
     . . `; -._    )-;-,_`)
    (v_,)'  _  )`-.\  ``-'
   _.- _..-_/ / ((.'
((,.-'   ((,/   fL




More information about the DB-SIG mailing list