Printing help docstring of all the functions in the string module: Python
I am trying to print all the functions
and their help docstrings
in the strings module
but am not getting the desired results. Below are the things which I have tried:
r = 'A random string'
1. [help(fn) for fn in r.__dir__() if not fn.startswith('__')]
2. [help(r.fn) for fn in r.__dir__() if not fn.startswith('__')]
3. [fn.__doc__ for fn in r.__dir__() if not fn.startswith('__')]
4. [r.fn.__doc__ for fn in r.__dir__() if not fn.startswith('__')]
and a few things more. Some of them throw errors saying that r
does not have attribute named 'fn'
. Others just print the help documentation for the 'str'
function. Is there any way I can print this for all the functions dynamically?
python docstring
add a comment |
I am trying to print all the functions
and their help docstrings
in the strings module
but am not getting the desired results. Below are the things which I have tried:
r = 'A random string'
1. [help(fn) for fn in r.__dir__() if not fn.startswith('__')]
2. [help(r.fn) for fn in r.__dir__() if not fn.startswith('__')]
3. [fn.__doc__ for fn in r.__dir__() if not fn.startswith('__')]
4. [r.fn.__doc__ for fn in r.__dir__() if not fn.startswith('__')]
and a few things more. Some of them throw errors saying that r
does not have attribute named 'fn'
. Others just print the help documentation for the 'str'
function. Is there any way I can print this for all the functions dynamically?
python docstring
add a comment |
I am trying to print all the functions
and their help docstrings
in the strings module
but am not getting the desired results. Below are the things which I have tried:
r = 'A random string'
1. [help(fn) for fn in r.__dir__() if not fn.startswith('__')]
2. [help(r.fn) for fn in r.__dir__() if not fn.startswith('__')]
3. [fn.__doc__ for fn in r.__dir__() if not fn.startswith('__')]
4. [r.fn.__doc__ for fn in r.__dir__() if not fn.startswith('__')]
and a few things more. Some of them throw errors saying that r
does not have attribute named 'fn'
. Others just print the help documentation for the 'str'
function. Is there any way I can print this for all the functions dynamically?
python docstring
I am trying to print all the functions
and their help docstrings
in the strings module
but am not getting the desired results. Below are the things which I have tried:
r = 'A random string'
1. [help(fn) for fn in r.__dir__() if not fn.startswith('__')]
2. [help(r.fn) for fn in r.__dir__() if not fn.startswith('__')]
3. [fn.__doc__ for fn in r.__dir__() if not fn.startswith('__')]
4. [r.fn.__doc__ for fn in r.__dir__() if not fn.startswith('__')]
and a few things more. Some of them throw errors saying that r
does not have attribute named 'fn'
. Others just print the help documentation for the 'str'
function. Is there any way I can print this for all the functions dynamically?
python docstring
python docstring
asked Jan 1 at 13:58


Gsbansal10Gsbansal10
1085
1085
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
In python2:
for i in dir(r):
if not i.startswith('__'):
print getattr(r, i).__doc__
In python3:
for i in dir(r):
if not i.startswith('__'):
print(getattr(r, i).__doc__)
(it's basically the same, changes the print
function only). You need to get the method object wth getattr
in order to show its __doc__
attribute.
add a comment |
To print the docstring you use func.__doc__.
r = 'A random string'
for fn in r.__dir__():
if not fn.startswith("__"):
print ("Function:",fn)
print (fn.__doc__)
print()
Have you even tried running your code. There is an error in your first print statement. It should beprint("Function: %s" %fn)
. Furthermore, this code only prints the documentation ofstr
function multiple times. Please check it once again and revert.
– Gsbansal10
Jan 1 at 16:34
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996057%2fprinting-help-docstring-of-all-the-functions-in-the-string-module-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In python2:
for i in dir(r):
if not i.startswith('__'):
print getattr(r, i).__doc__
In python3:
for i in dir(r):
if not i.startswith('__'):
print(getattr(r, i).__doc__)
(it's basically the same, changes the print
function only). You need to get the method object wth getattr
in order to show its __doc__
attribute.
add a comment |
In python2:
for i in dir(r):
if not i.startswith('__'):
print getattr(r, i).__doc__
In python3:
for i in dir(r):
if not i.startswith('__'):
print(getattr(r, i).__doc__)
(it's basically the same, changes the print
function only). You need to get the method object wth getattr
in order to show its __doc__
attribute.
add a comment |
In python2:
for i in dir(r):
if not i.startswith('__'):
print getattr(r, i).__doc__
In python3:
for i in dir(r):
if not i.startswith('__'):
print(getattr(r, i).__doc__)
(it's basically the same, changes the print
function only). You need to get the method object wth getattr
in order to show its __doc__
attribute.
In python2:
for i in dir(r):
if not i.startswith('__'):
print getattr(r, i).__doc__
In python3:
for i in dir(r):
if not i.startswith('__'):
print(getattr(r, i).__doc__)
(it's basically the same, changes the print
function only). You need to get the method object wth getattr
in order to show its __doc__
attribute.
answered Jan 1 at 15:20
ValentinoValentino
1,0041715
1,0041715
add a comment |
add a comment |
To print the docstring you use func.__doc__.
r = 'A random string'
for fn in r.__dir__():
if not fn.startswith("__"):
print ("Function:",fn)
print (fn.__doc__)
print()
Have you even tried running your code. There is an error in your first print statement. It should beprint("Function: %s" %fn)
. Furthermore, this code only prints the documentation ofstr
function multiple times. Please check it once again and revert.
– Gsbansal10
Jan 1 at 16:34
add a comment |
To print the docstring you use func.__doc__.
r = 'A random string'
for fn in r.__dir__():
if not fn.startswith("__"):
print ("Function:",fn)
print (fn.__doc__)
print()
Have you even tried running your code. There is an error in your first print statement. It should beprint("Function: %s" %fn)
. Furthermore, this code only prints the documentation ofstr
function multiple times. Please check it once again and revert.
– Gsbansal10
Jan 1 at 16:34
add a comment |
To print the docstring you use func.__doc__.
r = 'A random string'
for fn in r.__dir__():
if not fn.startswith("__"):
print ("Function:",fn)
print (fn.__doc__)
print()
To print the docstring you use func.__doc__.
r = 'A random string'
for fn in r.__dir__():
if not fn.startswith("__"):
print ("Function:",fn)
print (fn.__doc__)
print()
answered Jan 1 at 14:57
MarkReedZMarkReedZ
9267
9267
Have you even tried running your code. There is an error in your first print statement. It should beprint("Function: %s" %fn)
. Furthermore, this code only prints the documentation ofstr
function multiple times. Please check it once again and revert.
– Gsbansal10
Jan 1 at 16:34
add a comment |
Have you even tried running your code. There is an error in your first print statement. It should beprint("Function: %s" %fn)
. Furthermore, this code only prints the documentation ofstr
function multiple times. Please check it once again and revert.
– Gsbansal10
Jan 1 at 16:34
Have you even tried running your code. There is an error in your first print statement. It should be
print("Function: %s" %fn)
. Furthermore, this code only prints the documentation of str
function multiple times. Please check it once again and revert.– Gsbansal10
Jan 1 at 16:34
Have you even tried running your code. There is an error in your first print statement. It should be
print("Function: %s" %fn)
. Furthermore, this code only prints the documentation of str
function multiple times. Please check it once again and revert.– Gsbansal10
Jan 1 at 16:34
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996057%2fprinting-help-docstring-of-all-the-functions-in-the-string-module-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown