detecting param type

Jason Cunliffe jasonic at nomadicsltd.com
Wed Oct 25 14:35:03 EDT 2000


Hello

newbie type question.. I am sure this is very basic but I cant see how..

I am writing some functions to  create dictionaries whose lookup keys are
datetimestamps. These need to be strings, but are derived from DateTime
objects built using the lovely mxDateTime. I have a class Caldict [calendar
dictionary] and I want to to be able to pass in params which are either
datetime objects or strings, and have my methods be smart and friendly
enough to do the detection itself.

For example inside my class Caldict I have a method append

def append(self, date=str(now()), entry='entry', display=0):
        s = self.eventdict
       # Q: how to detect if date param is already a string or a datetime
object ?
        s.append(date, entry)
        if display:
            self.display()

at the moment I can do the following:

>>> from DateTime import *
>>> import caldict
>>> s = caldict.Caldict #initialize a calendar dictionary
>>> s.append(str(DateTimeFrom(year= -2500)),entry = 'bronze age')
>>> s.append('2001-10-22 13:55:15.94', entry = 'right here and now')


I need to modify my append method to become something like:

def append(self, date=now(), entry='entry', display=0):
        s = self.eventdict
       # detect if date param is already a string or a datetime object
       if type(date) == 'DateTime':   ### <<< this is the one I need help
with
            date = str(date)
        s.append(date, entry)
        if display:
            self.display()

Thanks for any help on this

 Jason

PS: <PLEASE make mxDateTime a standard art of Python distribution>

--
________________________________________________________________
Jason CUNLIFFE = NOMADICS['Interactive Art and Technology'].DesignDirector






More information about the Python-list mailing list