Unbound methods of types

Christian Tanzer tanzer at swing.co.at
Mon Apr 30 04:11:59 EDT 2001


Ben Hutchings <ben.hutchings at roundpoint.com> wrote:

> Let me try to explain myself more clearly.  If strings were instances
> of a class String, I could say String.foo to get the unbound string
> method foo; as it is, there happens to be a string module so I can say
> string.foo to get a function that works as if it were the unbound
> string method (except where foo = join).  For other sequences such as
> lists, there is no such module to help.  To pick a better example, I
> can't say:
> 
>     map(types.DictType.keys, [{'a':1,'b':2,'c':3}, {'d':4,'e':5,'f':6}])
> 
> and get back something like:
> 
>     [['b', 'c', 'a'], ['f', 'd', 'e']]

Doing this is a bad idea. If you map an unbound method, any
polymorphism is lost (e.g., a UserDict instance in the list passed to
map would not work). 

-- 
Christian Tanzer                                         tanzer at swing.co.at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92





More information about the Python-list mailing list