tags:

views:

41

answers:

2

Why doesn't

import string;help(string.title) 

seem to work but

help(string.strip)

works just fine?

I get the error

Traceback (most recent call last):
File "", line 1, in AttributeError: 'module' object has no attribute 'title'

+1  A: 

help(str.title) seems to work just fine.

Ignacio Vazquez-Abrams
There must be some sort of distinction between str and string that I will need to read about then, thanks.
wp123
str is inbuilt, `string` is a module
ghostdog74
`str` is the type of string literals.
Ignacio Vazquez-Abrams
+2  A: 

title is a method on objects of type str, not a function in the string module. That means you can do "foo".title() or str.title("foo") but not string.title("foo").

Gabe
Type `str`, not `string`.
Ignacio Vazquez-Abrams
Good point Ignacio, thanks.
Gabe