Printing help docstring of all the functions in the string module: Python












1















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?










share|improve this question



























    1















    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?










    share|improve this question

























      1












      1








      1








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 1 at 13:58









      Gsbansal10Gsbansal10

      1085




      1085
























          2 Answers
          2






          active

          oldest

          votes


















          1














          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.






          share|improve this answer































            0














            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()





            share|improve this answer
























            • 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











            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            1














            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.






            share|improve this answer




























              1














              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.






              share|improve this answer


























                1












                1








                1







                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.






                share|improve this answer













                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 1 at 15:20









                ValentinoValentino

                1,0041715




                1,0041715

























                    0














                    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()





                    share|improve this answer
























                    • 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
















                    0














                    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()





                    share|improve this answer
























                    • 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














                    0












                    0








                    0







                    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()





                    share|improve this answer













                    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()






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










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

















                    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


















                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith