'capwords' is not a string method 
Author Message
 'capwords' is not a string method

Here is something I very recently discovered . . . "capwords" are not
included as a method of the string type, but "upcase" is:  

Quote:
>>> str = "python rocks"
>>> str.capwords()

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  AttributeError: 'str' object has no attribute 'capwords'
Quote:
>>> str.upper()

'PYTHON ROCKS'

But "capwords" *is* included in the string module:

Quote:
>>> string.capwords(str)

'Python Rocks'

So I can still do it, but this seems a little inconsistant to me.  Is
there a reason, or is it just an oversight??

-- mikeh

--
Mike Hostetler          

http://www.*-*-*.com/
GnuPG key: http://www.*-*-*.com/



Mon, 03 Jan 2005 05:23:51 GMT  
 'capwords' is not a string method
        ...

Quote:
> But "capwords" *is* included in the string module:

>>>> string.capwords(str)
> 'Python Rocks'

> So I can still do it, but this seems a little inconsistant to me.  Is
> there a reason, or is it just an oversight??

> -- mikeh
>>> import string
>>> string.capwords('python/rocks')
'Python/rocks'
>>> 'python/rocks'.title()
'Python/Rocks'

Apparently, they took occasion of the introduction of string
methods to replace the semi-crippled capwords (which only
capitalizes words _preceded by whitespace_) with the better
method title, which capitalizes words even when they are
preceded by punctuation, as well as whitespace.  It seems
sensible to me -- the need met by .title() is more frequent,
and if the issue is backwards compatibility, capwords is
still around (in the semi-obsolescent string module -- only
semi, because it supplies crucial constants such as digits,
letters, whitespace, etc).

Alex



Mon, 03 Jan 2005 05:42:15 GMT  
 'capwords' is not a string method

Quote:

> Here is something I very recently discovered . . . "capwords" are not
> included as a method of the string type, but "upcase" is:  

my guess is the implementation for Unicode was not straight forward.  Or
perhaps they felt that not every method of the string library needed to be
implemented on the new objects.


Mon, 03 Jan 2005 05:34:04 GMT  
 'capwords' is not a string method

Quote:

> Apparently, they took occasion of the introduction of string
> methods to replace the semi-crippled capwords (which only
> capitalizes words _preceded by whitespace_) with the better
> method title, which capitalizes words even when they are
> preceded by punctuation, as well as whitespace.  It seems
> sensible to me -- the need met by .title() is more frequent,
> and if the issue is backwards compatibility, capwords is
> still around (in the semi-obsolescent string module -- only
> semi, because it supplies crucial constants such as digits,
> letters, whitespace, etc).

I didn't know about the 'title' method . . .I'll try that.  I'd rather
use string's built-in methods than (how you put it) the semi-obsolescent
string module.

-- mikeh

--
Mike Hostetler          

http://www.binary.net/thehaas
GnuPG key: http://www.binary.net/thehaas/mikeh.gpg



Mon, 03 Jan 2005 06:38:19 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. STRING 'make'/'remake'

2. Getting Ascii string from hex 'string'

3. Questions on 1.6a2's string methods

4. String Methods Don't Change ID?

5. 'who am i' from unix

6. buglet in string.capwords...

7. why am i always typing #'string= instead of 'string=?

8. LabVIEW's equivalent to Excel's GoalSeek method

9. Method type 'abstract'

10. vrml 2.0 activeX control that allows java methods to access container's methods

11. 'bind' functions into methods

12. Invoking a subclass's method on its superclass's instance

 

 
Powered by phpBB® Forum Software