interactive help on string functions - howto
Jeff Shannon
jeff at ccvcorp.com
Wed Sep 29 16:30:25 EDT 2004
Helmut Jarausch wrote:
> Many thanks for the hint.
>
> Still I wonder why I have to prefix it with 'str.'
> I don't need to import str and I don't need to prefix rstrip
> with 'str.' to USE it - why do I have to do so with HELP then?
But you *do* prefix rstrip() with *a* str when you use it.
rstrip() is a string method. Strings are of type 'str'. So an
expression like
"my text".rstrip()
is exactly equivalent to
str.rstrip("my text")
as can easily be demonstrated.
>>> str.rstrip('foo! ')
'foo!'
>>> 'foo! '.rstrip()
'foo!'
>>>
Python doesn't know where rstrip() is unless you *tell* it that it's a
string method. When you're calling it, you're telling it that it's a
string method by calling it from an instance of type str. When passing
it to help(), you need to tell it that it's a string method by
prepending 'str.' to it.
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list