A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/064140.html below:

Unbound methods of types

Unbound methods of types Unbound methods of typesSteve Holden sholden at holdenweb.com
Sun Apr 29 19:16:23 EDT 2001
"Ben Hutchings" <ben.hutchings at roundpoint.com> wrote in message
news:uwv831f2r.fsf_-_ at roundpoint.com...
> "Alex Martelli" <aleaxit at yahoo.com> writes:
> <snip>
> > # 4. special case, as you note, for string. stuff
> > L = map(string.capitalize, l)
> <snip>
>
> I feel that it ought to be possible to use type("").capitalize here,
> as one could do with a class method.  Why is it not possible to get
> unbound methods from types?  Should it be?
>
type("") is of type type, not type string. You can apply the str() function
to it, but this will give you a method with the string instance bound to it:

>>> type("")
<type 'string'>
>>> str(type(""))
"<type 'string'>"
>>> x = str(type("")).upper
>>> x()
"<TYPE 'STRING'>"
>>> x("A banana")
Traceback (innermost last):
  File "<interactive input>", line 1, in ?
TypeError: upper requires exactly 0 arguments; 1 given

regards
 Steve



More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4