struct_time type testing 2.1-2.2

Robin Becker robin at jessikat.fsnet.co.uk
Thu Feb 28 12:06:05 EST 2002


Jeff Bauer kindly tells me that Python 2.2 has a different return type
for time.localtime(...). 

In his module he had a test on an argument type of the form

    _SeqTypes = (ListType,TupleType)


    tn = type(arg)
    if tn in _SeqTypes:
      self.normalDate = int("%04d%02d%02d" % normalDate[:3])

and in 2.2 we seem to need 

    if tn in _SeqTypes or tn is time.struct_time:

is there a cleverer way than

    if tn in _SeqTypes or tn is getatr(time,'struct_time',None):

to get a cross version test?

Presumably we could extend _SeqTypes as that needs to be done only once,
but ideally a simple check like

        arg.supports_index(3)

would be more informative than defining these rather arbitrary named
type lists.
-- 
Robin Becker



More information about the Python-list mailing list