Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > interactive help on string functions - howto

Reply
Thread Tools

interactive help on string functions - howto

 
 
Helmut Jarausch
Guest
Posts: n/a
 
      09-29-2004
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
 
Reply With Quote
 
 
 
 
Jeremy Jones
Guest
Posts: n/a
 
      09-29-2004
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
 
Reply With Quote
 
 
 
 
George Yoshida
Guest
Posts: n/a
 
      09-29-2004
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
 
Reply With Quote
 
Steven Bethard
Guest
Posts: n/a
 
      09-29-2004
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

 
Reply With Quote
 
Steven Bethard
Guest
Posts: n/a
 
      09-29-2004
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

 
Reply With Quote
 
Jeff Shannon
Guest
Posts: n/a
 
      09-29-2004
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

 
Reply With Quote
 
Thomas Heller
Guest
Posts: n/a
 
      09-29-2004
Helmut Jarausch <(E-Mail Removed)> 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
 
Reply With Quote
 
Helmut Jarausch
Guest
Posts: n/a
 
      09-29-2004
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
 
Reply With Quote
 
Helmut Jarausch
Guest
Posts: n/a
 
      09-29-2004
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
 
Reply With Quote
 
Paul McNett
Guest
Posts: n/a
 
      09-29-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie: Non-interactive status displays - HOWTO? Chris Perl 3 02-18-2008 04:04 AM
Interactive/Non-interactive ASPX ? WJ ASP .Net 2 02-26-2005 02:54 AM
non Interactive and Interactive AAH Computer Support 0 01-09-2005 04:09 PM
Interactive and non interactive AAH Computer Support 1 01-09-2005 04:01 PM
please help me in distinguish redefining functions, overloading functions and overriding functions. Xiangliang Meng C++ 1 06-21-2004 03:11 AM



Advertisments