471,073 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

interactive help on string functions - howto

Hi,

entering
help('rstrip')
or
help('ljust')

into IDLE's shell window I only get
no Python documentation found ...

Am I missing something?

Thanks for a hint,
Helmut.

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
Jul 18 '05 #1
11 2643
Helmut Jarausch wrote:
Hi,

entering
help('rstrip')
or
help('ljust')

into IDLE's shell window I only get
no Python documentation found ...

Am I missing something?

Thanks for a hint,
Helmut.


Make sure you've imported string. Then you can do:
help(string.rstrip)

Help on function rstrip in module string:

rstrip(s, chars=None)
rstrip(s [,chars]) -> string

Return a copy of the string s with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
Jeremy Jones
Jul 18 '05 #2
Jeremy Jones <zanesdad <at> bellsouth.net> writes:
Make sure you've imported string.


No need to import string, you can use the builtin str:
help(str.rstrip) Help on method_descriptor:

rstrip(...)
S.rstrip([chars]) -> string or unicode

Return a copy of the string S with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
If chars is unicode, S will be converted to unicode before stripping
help(str.ljust)

Help on method_descriptor:

ljust(...)
S.ljust(width[, fillchar]) -> string

Return S left justified in a string of length width. Padding is
done using the specified fill character (default is a space).
Steve

Jul 18 '05 #3
Helmut Jarausch wrote:
entering
help('rstrip')
or
help('ljust')

into IDLE's shell window I only get
no Python documentation found ...

Am I missing something?


You need to remove quotes from arguments, i.e.,
help(rstrip) # help('rstrip') is a no-no


I have to say this error message is really annoying. You can't
guess what went wrong from it.
George
Jul 18 '05 #4
George Yoshida <ml <at> dynkin.com> writes:

I have to say this error message is really annoying. You can't
guess what went wrong from it.


Yeah, maybe it would be clearer if it said something like "No Python
documentation found for module, keyword or topic 'rstrip'" That would make it
clearer that you can only use a string if the string is the name of a module,
keyword or a topic (not a function like the OP's example).

STeve

Jul 18 '05 #5
George Yoshida wrote:
Helmut Jarausch wrote:
entering
help('rstrip')
or
help('ljust')

into IDLE's shell window I only get
no Python documentation found ...

Am I missing something?

You need to remove quotes from arguments, i.e.,
help(rstrip) # help('rstrip') is a no-no

But note that help(rstrip) doesn't provide any useful help either:
help(rstrip) Traceback (most recent call last):
File "<interactive input>", line 1, in ?
NameError: name 'rstrip' is not defined


What's needed is help(str.rstrip), which does indeed work. (As already
pointed out by other posters.)

Jeff Shannon
Technician/Programmer
Credit International

Jul 18 '05 #6
Helmut Jarausch <ja******@skynet.be> writes:
Hi,

entering
help('rstrip')
or
help('ljust')

into IDLE's shell window I only get
no Python documentation found ...

Am I missing something?


If you install the Python HTML pages in the correct place, it will
indeed work this way.

Or you press F1, and enter rstrip in the CHM search box (on Windows).

Thomas
Jul 18 '05 #7
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?

Steven Bethard wrote:
Jeremy Jones <zanesdad <at> bellsouth.net> writes:
Make sure you've imported string.

No need to import string, you can use the builtin str:

help(str.rstrip)
Help on method_descriptor:

rstrip(...)
S.rstrip([chars]) -> string or unicode

Return a copy of the string S with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
If chars is unicode, S will be converted to unicode before stripping

help(str.ljust)


Help on method_descriptor:

ljust(...)
S.ljust(width[, fillchar]) -> string

Return S left justified in a string of length width. Padding is
done using the specified fill character (default is a space).

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
Jul 18 '05 #8
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?

Steven Bethard wrote:
Jeremy Jones <zanesdad <at> bellsouth.net> writes:
Make sure you've imported string.

No need to import string, you can use the builtin str:

help(str.rstrip)
Help on method_descriptor:

rstrip(...)
S.rstrip([chars]) -> string or unicode

Return a copy of the string S with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
If chars is unicode, S will be converted to unicode before stripping

help(str.ljust)


Help on method_descriptor:

ljust(...)
S.ljust(width[, fillchar]) -> string

Return S left justified in a string of length width. Padding is
done using the specified fill character (default is a space).

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
Jul 18 '05 #9
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

Jul 18 '05 #10
Helmut Jarausch writes:
Still I wonder why I have to prefix it with 'str.'
Because the only builtin identifiers are:
for name in dir(__builtins__): .... print name
ArithmeticError
AssertionError
.... [snip]
vars
xrange
zip

rstrip isn't a builtin, but a method of the str class. str is
builtin. Hence, to access rstrip(), you have to call it as a
method of a string class or instance.
s = "mango"
help(s.rstrip)
help(str.rstrip)
Both calls to help will yield the same documentation. help() is
a builtin function, which is why you don't have to preface that
with anything.
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?


You *do* have to prefix rstrip, with a str class or instance.
rstrip Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'rstrip' is not defined
str.rstrip <method 'rstrip' of 'str' objects>
s = "cashew"
s.rstrip

<built-in method rstrip of str object at 0x40177780>

Mmmmm. Time for lunch. :)

--
Paul McNett
Independent Software Consultant
http://www.paulmcnett.com
Jul 18 '05 #11

Helmut> Still I wonder why I have to prefix it with 'str.' I don't need
Helmut> to import str and I don't need to prefix rstrip with 'str.' to
Helmut> USE it - why do I have to do so with HELP then?

You need to prefix rstrip with a string instance or type (class). "str" is
to readily available type (class). You could also execute

help("".rstrip)

Skip
Jul 18 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by SeeBelow | last post: by
37 posts views Thread by Shri | last post: by
5 posts views Thread by sugaray | last post: by
2 posts views Thread by WJ | last post: by
4 posts views Thread by j_macaroni | last post: by
4 posts views Thread by Jim Langston | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.