472,805 Members | 917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 2788
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: SeeBelow | last post by:
Is there any way, in C, of interacting with a running program, but still using code that is portable, at least between linux and Windows? By "interacting" it could be something as simple as...
37
by: Shri | last post by:
hi all, i am writing a code in which i have a char buffer "cwdir" which hold the current working directory by calling the function getcwd(). later i change the directory to "/" as i have to make...
5
by: sugaray | last post by:
Right now, the code I wrote below seems works fine, i know it's definitely not the best solution, so if there are better solutions to eschew from using goto statements to jump out of multiple loops...
2
by: WJ | last post by:
I have three ASPX pages: 1. "WebForm1.aspx" is interactive, responsible for calling a web site (https://www.payMe.com) with $$$. It is working fine. 2. "WebForm2.aspx" is non-interactive, a...
3
by: Coffee | last post by:
I have asked this before, but the offered solution did not work. I want to have a command button, that transfers any text from a textbox to a variable which is an array. so that i can print out...
4
by: j_macaroni | last post by:
I know you can start php -a and go into interactive mode. This works well exept you have to keep putting <?php code here ; bla blah code ; Couple of problems with this. 1) Exits php when you...
4
by: Jim Langston | last post by:
Is there any builtin lowercase std::string compare? Right now I'm doing this: if ( _stricmp( AmmoTypeText.c_str(), "GunBullet" ) == 0 ) AmmoType = Item_Ammo_GunBullet; Is there anything the...
0
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not...
7
by: dmitrey | last post by:
hi all, can anyone explain howto get function from module, known by string names? I.e. something like def myfunc(module_string1, func_string2, *args): eval('from ' + module_string1 + 'import...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.