In article <[EMAIL PROTECTED]>, Duncan Booth <[EMAIL PROTECTED]> wrote:
> Roy Smith wrote: > > > In 3.0, can you still order types? In 2.x, you can do: > > > >>>> t1 = type(1) > >>>> t2 = type(1j) > >>>> t1 < t2 > > False > > > > If this still works in 3.0, then you can easily do something like: > > > > def total_order(o1, o2): > > "Compare any two objects of arbitrary types" > > try: > > return o1 <= o2 > > except UncomparableTypesError: # whatever the right name is > > return type(o1) <= type(o2) > > > > and get the same effect as you had in 2.x. > > No, that won't work. You can compare types for equality/inequality, but > they are not orderable: > > >>> type(1)==type('a') > False > >>> sorted([1, 'a'], key=lambda x:(type(x),x)) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: unorderable types: type() < type() Sigh. So if I really wanted to do that, I'd be forced to write "str(type(o1)) < str(type(o2))"? To me, that sounds suspiciously like "sudo type(o1) < type(o2)" :-) -- http://mail.python.org/mailman/listinfo/python-list