interactive help on string functions - howto

H

Helmut Jarausch

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
 
J

Jeremy Jones

Helmut said:
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 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
 
G

George Yoshida

Helmut said:
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.,
I have to say this error message is really annoying. You can't
guess what went wrong from it.


George
 
S

Steven Bethard

Jeremy Jones said:
Make sure you've imported string.

No need to import string, you can use the builtin str:
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 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
 
S

Steven Bethard

George Yoshida said:
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
 
J

Jeff Shannon

George said:
You need to remove quotes from arguments, i.e.,


But note that help(rstrip) doesn't provide any useful help either:
Traceback (most recent call last):

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

Jeff Shannon
Technician/Programmer
Credit International
 
T

Thomas Heller

Helmut Jarausch said:
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
 
H

Helmut Jarausch

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 said:
Jeremy Jones said:
Make sure you've imported string.


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


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 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
 
H

Helmut Jarausch

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 said:
Jeremy Jones said:
Make sure you've imported string.


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


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 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
 
P

Paul McNett

Helmut said:
Still I wonder why I have to prefix it with 'str.'

Because the only builtin identifiers are:
.... 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.

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.
Traceback (most recent call last):
<built-in method rstrip of str object at 0x40177780>

Mmmmm. Time for lunch. :)
 
J

Jeff Shannon

Helmut said:
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.

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
 
S

Skip Montanaro

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top