Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python help() function and the string.title function

Tags:

python

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'

like image 263
wp123 Avatar asked Mar 14 '26 14:03

wp123


2 Answers

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").

like image 178
Gabe Avatar answered Mar 16 '26 03:03

Gabe


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

like image 34
Ignacio Vazquez-Abrams Avatar answered Mar 16 '26 04:03

Ignacio Vazquez-Abrams