How do I export the output of Python's built-in help() function











up vote
12
down vote

favorite
3












I've got a python package which outputs considerable help text from: help(package)



I would like to export this help text to a file, in the format in which it's displayed by help(package)



How might I go about this?










share|improve this question




















  • 3




    Do you know about the pydoc module?
    – DSM
    Jun 29 '12 at 16:36















up vote
12
down vote

favorite
3












I've got a python package which outputs considerable help text from: help(package)



I would like to export this help text to a file, in the format in which it's displayed by help(package)



How might I go about this?










share|improve this question




















  • 3




    Do you know about the pydoc module?
    – DSM
    Jun 29 '12 at 16:36













up vote
12
down vote

favorite
3









up vote
12
down vote

favorite
3






3





I've got a python package which outputs considerable help text from: help(package)



I would like to export this help text to a file, in the format in which it's displayed by help(package)



How might I go about this?










share|improve this question















I've got a python package which outputs considerable help text from: help(package)



I would like to export this help text to a file, in the format in which it's displayed by help(package)



How might I go about this?







python helper pydoc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 31 at 17:01









Clifford

63




63










asked Jun 29 '12 at 16:31









ipmcc

25.9k272124




25.9k272124








  • 3




    Do you know about the pydoc module?
    – DSM
    Jun 29 '12 at 16:36














  • 3




    Do you know about the pydoc module?
    – DSM
    Jun 29 '12 at 16:36








3




3




Do you know about the pydoc module?
– DSM
Jun 29 '12 at 16:36




Do you know about the pydoc module?
– DSM
Jun 29 '12 at 16:36












8 Answers
8






active

oldest

votes

















up vote
5
down vote



accepted










This is a bit hackish (and there's probably a better solution somewhere), but this works:



import sys
import pydoc

def output_help_to_file(filepath, request):
f = open(filepath, 'w')
sys.stdout = f
pydoc.help(request)
f.close()
sys.stdout = sys.__stdout__
return


And then...



>>> output_help_to_file(r'test.txt', 're')





share|improve this answer






























    up vote
    15
    down vote













    pydoc.render_doc(thing) to get thing's help text as a string. Other parts of pydoc like pydoc.text and pydoc.html can help you write it to a file.



    Using the -w modifier in linux will write the output to a html in the current directory, for example;



    pydoc -w Rpi.GPIO


    Puts all the help() text that would be presented from the command help(Rpi.GPIO) into a nicely formatted file Rpi.GPIO.html, in the current directory of the shell






    share|improve this answer



















    • 4




      This is actually a bit easier than the selected answer.
      – Michael Wu
      Jul 28 '14 at 15:15






    • 1




      I've found the selected answer to be not very good, using this post, I did a bit of research into pydocs and edited this answer with my exact solution
      – davidhood2
      Oct 13 '16 at 8:54










    • Nice, thanks. I didn't know there was a command line utility to go with it.
      – Aaron Altman
      Oct 18 '16 at 14:54


















    up vote
    1
    down vote













    If you do help(help) you'll see:



    Help on _Helper in module site object:

    class _Helper(__builtin__.object)
    | Define the builtin 'help'.
    | This is a wrapper around pydoc.help (with a twist).


    [rest snipped]



    So - you should be looking at the pydoc module - there's going to be a method or methods that return what help(something) does as a string...






    share|improve this answer




























      up vote
      0
      down vote













      In Windows, just open up a Windows Command Line window, go to the Lib subfolder of your Python installation, and type



      python pydoc.py moduleName.memberName > c:myFoldermemberName.txt



      to put the documentation for the property or method memberName in moduleName into the file memberName.txt. If you want an object further down the hierarchy of the module, just put more dots. For example



      python pydoc.py wx.lib.agw.ultimatelistctrl > c:myFolderUltimateListCtrl.txt



      to put the documentation on the UltimateListCtrl control in the agw package in the wxPython package into UltimateListCtrl.txt.






      share|improve this answer




























        up vote
        0
        down vote













        pydoc already provides the needed feature, a very well-designed feature that all question-answering systems should have. The pydoc.Helper.init has an output object, all output being sent there. If you use your own output object, you can do whatever you want. For example:



        class OUTPUT():



        def __init__(self):
        self.results =
        def write(self,text):
        self.results += [text]
        def flush(self):
        pass
        def print_(self):
        for x in self.results: print(x)
        def return_(self):
        return self.results
        def clear_(self):
        self.results =


        when passed as



        O = OUTPUT() # Necessarily to remember results, but see below.



        help = pydoc.Helper(O)



        will store all results in the OUTPUT instance. Of course, beginning with O = OUTPUT() is not the best idea (see below). render_doc is not the central output point; output is. I wanted OUTPUT so I could keep large outputs from disappearing from the screen using something like Mark Lutz' "More". A different OUTPUT would allow you to write to files.



        You could also add a "return" to the end of the class pydoc.Helper to return the information you want. Something like:



        if self.output_: return self.output_



        should work, or



        if self.output_: return self.output.return_()



        All of this is possible because pydoc is well-designed. It is hidden because the definition of help leaves out the input and output arguments.






        share|improve this answer






























          up vote
          0
          down vote













          An old question but the newer recommended generic solution (for Python 3.4+) for writing the output of functions that print() to terminal is using contextlib.redirect_stdout:



          import contextlib

          def write_help(func, out_file):
          with open(out_file, 'w') as f:
          with contextlib.redirect_stdout(f):
          help(func)


          Usage example:



          write_help(int, 'test.txt')





          share|improve this answer






























            up vote
            0
            down vote













            Selected answer didn't work for me, so I did a little more searching and found something that worked on Daniweb. Credit goes to vegaseat. https://www.daniweb.com/programming/software-development/threads/20774/starting-python/8#post1306519



            # simplified version of sending help() output to a file
            import sys
            # save present stdout
            out = sys.stdout
            fname = "help_print7.txt"
            # set stdout to file handle
            sys.stdout = open(fname, "w")
            # run your help code
            # its console output goes to the file now
            help("print")
            sys.stdout.close()
            # reset stdout
            sys.stdout = out





            share|improve this answer




























              up vote
              0
              down vote













              The simplest way to do that is via using




              sys module




              it opens a data stream between the operation system and it's self , it grab the data from the help module then save it in external file



              file="str.txt";file1="list.txt"
              out=sys.stdout
              sys.stdout=open('str_document','w')
              help(str)
              sys.stdout.close





              share|improve this answer





















                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',
                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%2f11265603%2fhow-do-i-export-the-output-of-pythons-built-in-help-function%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                8 Answers
                8






                active

                oldest

                votes








                8 Answers
                8






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                5
                down vote



                accepted










                This is a bit hackish (and there's probably a better solution somewhere), but this works:



                import sys
                import pydoc

                def output_help_to_file(filepath, request):
                f = open(filepath, 'w')
                sys.stdout = f
                pydoc.help(request)
                f.close()
                sys.stdout = sys.__stdout__
                return


                And then...



                >>> output_help_to_file(r'test.txt', 're')





                share|improve this answer



























                  up vote
                  5
                  down vote



                  accepted










                  This is a bit hackish (and there's probably a better solution somewhere), but this works:



                  import sys
                  import pydoc

                  def output_help_to_file(filepath, request):
                  f = open(filepath, 'w')
                  sys.stdout = f
                  pydoc.help(request)
                  f.close()
                  sys.stdout = sys.__stdout__
                  return


                  And then...



                  >>> output_help_to_file(r'test.txt', 're')





                  share|improve this answer

























                    up vote
                    5
                    down vote



                    accepted







                    up vote
                    5
                    down vote



                    accepted






                    This is a bit hackish (and there's probably a better solution somewhere), but this works:



                    import sys
                    import pydoc

                    def output_help_to_file(filepath, request):
                    f = open(filepath, 'w')
                    sys.stdout = f
                    pydoc.help(request)
                    f.close()
                    sys.stdout = sys.__stdout__
                    return


                    And then...



                    >>> output_help_to_file(r'test.txt', 're')





                    share|improve this answer














                    This is a bit hackish (and there's probably a better solution somewhere), but this works:



                    import sys
                    import pydoc

                    def output_help_to_file(filepath, request):
                    f = open(filepath, 'w')
                    sys.stdout = f
                    pydoc.help(request)
                    f.close()
                    sys.stdout = sys.__stdout__
                    return


                    And then...



                    >>> output_help_to_file(r'test.txt', 're')






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Sep 10 at 11:20









                    Adrian Gugyin

                    34




                    34










                    answered Jun 29 '12 at 17:05









                    Michael0x2a

                    21.8k1672125




                    21.8k1672125
























                        up vote
                        15
                        down vote













                        pydoc.render_doc(thing) to get thing's help text as a string. Other parts of pydoc like pydoc.text and pydoc.html can help you write it to a file.



                        Using the -w modifier in linux will write the output to a html in the current directory, for example;



                        pydoc -w Rpi.GPIO


                        Puts all the help() text that would be presented from the command help(Rpi.GPIO) into a nicely formatted file Rpi.GPIO.html, in the current directory of the shell






                        share|improve this answer



















                        • 4




                          This is actually a bit easier than the selected answer.
                          – Michael Wu
                          Jul 28 '14 at 15:15






                        • 1




                          I've found the selected answer to be not very good, using this post, I did a bit of research into pydocs and edited this answer with my exact solution
                          – davidhood2
                          Oct 13 '16 at 8:54










                        • Nice, thanks. I didn't know there was a command line utility to go with it.
                          – Aaron Altman
                          Oct 18 '16 at 14:54















                        up vote
                        15
                        down vote













                        pydoc.render_doc(thing) to get thing's help text as a string. Other parts of pydoc like pydoc.text and pydoc.html can help you write it to a file.



                        Using the -w modifier in linux will write the output to a html in the current directory, for example;



                        pydoc -w Rpi.GPIO


                        Puts all the help() text that would be presented from the command help(Rpi.GPIO) into a nicely formatted file Rpi.GPIO.html, in the current directory of the shell






                        share|improve this answer



















                        • 4




                          This is actually a bit easier than the selected answer.
                          – Michael Wu
                          Jul 28 '14 at 15:15






                        • 1




                          I've found the selected answer to be not very good, using this post, I did a bit of research into pydocs and edited this answer with my exact solution
                          – davidhood2
                          Oct 13 '16 at 8:54










                        • Nice, thanks. I didn't know there was a command line utility to go with it.
                          – Aaron Altman
                          Oct 18 '16 at 14:54













                        up vote
                        15
                        down vote










                        up vote
                        15
                        down vote









                        pydoc.render_doc(thing) to get thing's help text as a string. Other parts of pydoc like pydoc.text and pydoc.html can help you write it to a file.



                        Using the -w modifier in linux will write the output to a html in the current directory, for example;



                        pydoc -w Rpi.GPIO


                        Puts all the help() text that would be presented from the command help(Rpi.GPIO) into a nicely formatted file Rpi.GPIO.html, in the current directory of the shell






                        share|improve this answer














                        pydoc.render_doc(thing) to get thing's help text as a string. Other parts of pydoc like pydoc.text and pydoc.html can help you write it to a file.



                        Using the -w modifier in linux will write the output to a html in the current directory, for example;



                        pydoc -w Rpi.GPIO


                        Puts all the help() text that would be presented from the command help(Rpi.GPIO) into a nicely formatted file Rpi.GPIO.html, in the current directory of the shell







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Oct 13 '16 at 10:44









                        davidhood2

                        8001030




                        8001030










                        answered Jun 29 '12 at 17:35









                        Aaron Altman

                        1,29711118




                        1,29711118








                        • 4




                          This is actually a bit easier than the selected answer.
                          – Michael Wu
                          Jul 28 '14 at 15:15






                        • 1




                          I've found the selected answer to be not very good, using this post, I did a bit of research into pydocs and edited this answer with my exact solution
                          – davidhood2
                          Oct 13 '16 at 8:54










                        • Nice, thanks. I didn't know there was a command line utility to go with it.
                          – Aaron Altman
                          Oct 18 '16 at 14:54














                        • 4




                          This is actually a bit easier than the selected answer.
                          – Michael Wu
                          Jul 28 '14 at 15:15






                        • 1




                          I've found the selected answer to be not very good, using this post, I did a bit of research into pydocs and edited this answer with my exact solution
                          – davidhood2
                          Oct 13 '16 at 8:54










                        • Nice, thanks. I didn't know there was a command line utility to go with it.
                          – Aaron Altman
                          Oct 18 '16 at 14:54








                        4




                        4




                        This is actually a bit easier than the selected answer.
                        – Michael Wu
                        Jul 28 '14 at 15:15




                        This is actually a bit easier than the selected answer.
                        – Michael Wu
                        Jul 28 '14 at 15:15




                        1




                        1




                        I've found the selected answer to be not very good, using this post, I did a bit of research into pydocs and edited this answer with my exact solution
                        – davidhood2
                        Oct 13 '16 at 8:54




                        I've found the selected answer to be not very good, using this post, I did a bit of research into pydocs and edited this answer with my exact solution
                        – davidhood2
                        Oct 13 '16 at 8:54












                        Nice, thanks. I didn't know there was a command line utility to go with it.
                        – Aaron Altman
                        Oct 18 '16 at 14:54




                        Nice, thanks. I didn't know there was a command line utility to go with it.
                        – Aaron Altman
                        Oct 18 '16 at 14:54










                        up vote
                        1
                        down vote













                        If you do help(help) you'll see:



                        Help on _Helper in module site object:

                        class _Helper(__builtin__.object)
                        | Define the builtin 'help'.
                        | This is a wrapper around pydoc.help (with a twist).


                        [rest snipped]



                        So - you should be looking at the pydoc module - there's going to be a method or methods that return what help(something) does as a string...






                        share|improve this answer

























                          up vote
                          1
                          down vote













                          If you do help(help) you'll see:



                          Help on _Helper in module site object:

                          class _Helper(__builtin__.object)
                          | Define the builtin 'help'.
                          | This is a wrapper around pydoc.help (with a twist).


                          [rest snipped]



                          So - you should be looking at the pydoc module - there's going to be a method or methods that return what help(something) does as a string...






                          share|improve this answer























                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote









                            If you do help(help) you'll see:



                            Help on _Helper in module site object:

                            class _Helper(__builtin__.object)
                            | Define the builtin 'help'.
                            | This is a wrapper around pydoc.help (with a twist).


                            [rest snipped]



                            So - you should be looking at the pydoc module - there's going to be a method or methods that return what help(something) does as a string...






                            share|improve this answer












                            If you do help(help) you'll see:



                            Help on _Helper in module site object:

                            class _Helper(__builtin__.object)
                            | Define the builtin 'help'.
                            | This is a wrapper around pydoc.help (with a twist).


                            [rest snipped]



                            So - you should be looking at the pydoc module - there's going to be a method or methods that return what help(something) does as a string...







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jun 29 '12 at 16:42









                            Jon Clements

                            97.7k19172216




                            97.7k19172216






















                                up vote
                                0
                                down vote













                                In Windows, just open up a Windows Command Line window, go to the Lib subfolder of your Python installation, and type



                                python pydoc.py moduleName.memberName > c:myFoldermemberName.txt



                                to put the documentation for the property or method memberName in moduleName into the file memberName.txt. If you want an object further down the hierarchy of the module, just put more dots. For example



                                python pydoc.py wx.lib.agw.ultimatelistctrl > c:myFolderUltimateListCtrl.txt



                                to put the documentation on the UltimateListCtrl control in the agw package in the wxPython package into UltimateListCtrl.txt.






                                share|improve this answer

























                                  up vote
                                  0
                                  down vote













                                  In Windows, just open up a Windows Command Line window, go to the Lib subfolder of your Python installation, and type



                                  python pydoc.py moduleName.memberName > c:myFoldermemberName.txt



                                  to put the documentation for the property or method memberName in moduleName into the file memberName.txt. If you want an object further down the hierarchy of the module, just put more dots. For example



                                  python pydoc.py wx.lib.agw.ultimatelistctrl > c:myFolderUltimateListCtrl.txt



                                  to put the documentation on the UltimateListCtrl control in the agw package in the wxPython package into UltimateListCtrl.txt.






                                  share|improve this answer























                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote









                                    In Windows, just open up a Windows Command Line window, go to the Lib subfolder of your Python installation, and type



                                    python pydoc.py moduleName.memberName > c:myFoldermemberName.txt



                                    to put the documentation for the property or method memberName in moduleName into the file memberName.txt. If you want an object further down the hierarchy of the module, just put more dots. For example



                                    python pydoc.py wx.lib.agw.ultimatelistctrl > c:myFolderUltimateListCtrl.txt



                                    to put the documentation on the UltimateListCtrl control in the agw package in the wxPython package into UltimateListCtrl.txt.






                                    share|improve this answer












                                    In Windows, just open up a Windows Command Line window, go to the Lib subfolder of your Python installation, and type



                                    python pydoc.py moduleName.memberName > c:myFoldermemberName.txt



                                    to put the documentation for the property or method memberName in moduleName into the file memberName.txt. If you want an object further down the hierarchy of the module, just put more dots. For example



                                    python pydoc.py wx.lib.agw.ultimatelistctrl > c:myFolderUltimateListCtrl.txt



                                    to put the documentation on the UltimateListCtrl control in the agw package in the wxPython package into UltimateListCtrl.txt.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Mar 14 at 19:13









                                    JDMorganArkansas

                                    406




                                    406






















                                        up vote
                                        0
                                        down vote













                                        pydoc already provides the needed feature, a very well-designed feature that all question-answering systems should have. The pydoc.Helper.init has an output object, all output being sent there. If you use your own output object, you can do whatever you want. For example:



                                        class OUTPUT():



                                        def __init__(self):
                                        self.results =
                                        def write(self,text):
                                        self.results += [text]
                                        def flush(self):
                                        pass
                                        def print_(self):
                                        for x in self.results: print(x)
                                        def return_(self):
                                        return self.results
                                        def clear_(self):
                                        self.results =


                                        when passed as



                                        O = OUTPUT() # Necessarily to remember results, but see below.



                                        help = pydoc.Helper(O)



                                        will store all results in the OUTPUT instance. Of course, beginning with O = OUTPUT() is not the best idea (see below). render_doc is not the central output point; output is. I wanted OUTPUT so I could keep large outputs from disappearing from the screen using something like Mark Lutz' "More". A different OUTPUT would allow you to write to files.



                                        You could also add a "return" to the end of the class pydoc.Helper to return the information you want. Something like:



                                        if self.output_: return self.output_



                                        should work, or



                                        if self.output_: return self.output.return_()



                                        All of this is possible because pydoc is well-designed. It is hidden because the definition of help leaves out the input and output arguments.






                                        share|improve this answer



























                                          up vote
                                          0
                                          down vote













                                          pydoc already provides the needed feature, a very well-designed feature that all question-answering systems should have. The pydoc.Helper.init has an output object, all output being sent there. If you use your own output object, you can do whatever you want. For example:



                                          class OUTPUT():



                                          def __init__(self):
                                          self.results =
                                          def write(self,text):
                                          self.results += [text]
                                          def flush(self):
                                          pass
                                          def print_(self):
                                          for x in self.results: print(x)
                                          def return_(self):
                                          return self.results
                                          def clear_(self):
                                          self.results =


                                          when passed as



                                          O = OUTPUT() # Necessarily to remember results, but see below.



                                          help = pydoc.Helper(O)



                                          will store all results in the OUTPUT instance. Of course, beginning with O = OUTPUT() is not the best idea (see below). render_doc is not the central output point; output is. I wanted OUTPUT so I could keep large outputs from disappearing from the screen using something like Mark Lutz' "More". A different OUTPUT would allow you to write to files.



                                          You could also add a "return" to the end of the class pydoc.Helper to return the information you want. Something like:



                                          if self.output_: return self.output_



                                          should work, or



                                          if self.output_: return self.output.return_()



                                          All of this is possible because pydoc is well-designed. It is hidden because the definition of help leaves out the input and output arguments.






                                          share|improve this answer

























                                            up vote
                                            0
                                            down vote










                                            up vote
                                            0
                                            down vote









                                            pydoc already provides the needed feature, a very well-designed feature that all question-answering systems should have. The pydoc.Helper.init has an output object, all output being sent there. If you use your own output object, you can do whatever you want. For example:



                                            class OUTPUT():



                                            def __init__(self):
                                            self.results =
                                            def write(self,text):
                                            self.results += [text]
                                            def flush(self):
                                            pass
                                            def print_(self):
                                            for x in self.results: print(x)
                                            def return_(self):
                                            return self.results
                                            def clear_(self):
                                            self.results =


                                            when passed as



                                            O = OUTPUT() # Necessarily to remember results, but see below.



                                            help = pydoc.Helper(O)



                                            will store all results in the OUTPUT instance. Of course, beginning with O = OUTPUT() is not the best idea (see below). render_doc is not the central output point; output is. I wanted OUTPUT so I could keep large outputs from disappearing from the screen using something like Mark Lutz' "More". A different OUTPUT would allow you to write to files.



                                            You could also add a "return" to the end of the class pydoc.Helper to return the information you want. Something like:



                                            if self.output_: return self.output_



                                            should work, or



                                            if self.output_: return self.output.return_()



                                            All of this is possible because pydoc is well-designed. It is hidden because the definition of help leaves out the input and output arguments.






                                            share|improve this answer














                                            pydoc already provides the needed feature, a very well-designed feature that all question-answering systems should have. The pydoc.Helper.init has an output object, all output being sent there. If you use your own output object, you can do whatever you want. For example:



                                            class OUTPUT():



                                            def __init__(self):
                                            self.results =
                                            def write(self,text):
                                            self.results += [text]
                                            def flush(self):
                                            pass
                                            def print_(self):
                                            for x in self.results: print(x)
                                            def return_(self):
                                            return self.results
                                            def clear_(self):
                                            self.results =


                                            when passed as



                                            O = OUTPUT() # Necessarily to remember results, but see below.



                                            help = pydoc.Helper(O)



                                            will store all results in the OUTPUT instance. Of course, beginning with O = OUTPUT() is not the best idea (see below). render_doc is not the central output point; output is. I wanted OUTPUT so I could keep large outputs from disappearing from the screen using something like Mark Lutz' "More". A different OUTPUT would allow you to write to files.



                                            You could also add a "return" to the end of the class pydoc.Helper to return the information you want. Something like:



                                            if self.output_: return self.output_



                                            should work, or



                                            if self.output_: return self.output.return_()



                                            All of this is possible because pydoc is well-designed. It is hidden because the definition of help leaves out the input and output arguments.







                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited Jul 31 at 21:52

























                                            answered Jul 30 at 22:12









                                            Clifford

                                            63




                                            63






















                                                up vote
                                                0
                                                down vote













                                                An old question but the newer recommended generic solution (for Python 3.4+) for writing the output of functions that print() to terminal is using contextlib.redirect_stdout:



                                                import contextlib

                                                def write_help(func, out_file):
                                                with open(out_file, 'w') as f:
                                                with contextlib.redirect_stdout(f):
                                                help(func)


                                                Usage example:



                                                write_help(int, 'test.txt')





                                                share|improve this answer



























                                                  up vote
                                                  0
                                                  down vote













                                                  An old question but the newer recommended generic solution (for Python 3.4+) for writing the output of functions that print() to terminal is using contextlib.redirect_stdout:



                                                  import contextlib

                                                  def write_help(func, out_file):
                                                  with open(out_file, 'w') as f:
                                                  with contextlib.redirect_stdout(f):
                                                  help(func)


                                                  Usage example:



                                                  write_help(int, 'test.txt')





                                                  share|improve this answer

























                                                    up vote
                                                    0
                                                    down vote










                                                    up vote
                                                    0
                                                    down vote









                                                    An old question but the newer recommended generic solution (for Python 3.4+) for writing the output of functions that print() to terminal is using contextlib.redirect_stdout:



                                                    import contextlib

                                                    def write_help(func, out_file):
                                                    with open(out_file, 'w') as f:
                                                    with contextlib.redirect_stdout(f):
                                                    help(func)


                                                    Usage example:



                                                    write_help(int, 'test.txt')





                                                    share|improve this answer














                                                    An old question but the newer recommended generic solution (for Python 3.4+) for writing the output of functions that print() to terminal is using contextlib.redirect_stdout:



                                                    import contextlib

                                                    def write_help(func, out_file):
                                                    with open(out_file, 'w') as f:
                                                    with contextlib.redirect_stdout(f):
                                                    help(func)


                                                    Usage example:



                                                    write_help(int, 'test.txt')






                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Aug 17 at 8:59

























                                                    answered Aug 17 at 8:47









                                                    Chris_Rands

                                                    15.1k53868




                                                    15.1k53868






















                                                        up vote
                                                        0
                                                        down vote













                                                        Selected answer didn't work for me, so I did a little more searching and found something that worked on Daniweb. Credit goes to vegaseat. https://www.daniweb.com/programming/software-development/threads/20774/starting-python/8#post1306519



                                                        # simplified version of sending help() output to a file
                                                        import sys
                                                        # save present stdout
                                                        out = sys.stdout
                                                        fname = "help_print7.txt"
                                                        # set stdout to file handle
                                                        sys.stdout = open(fname, "w")
                                                        # run your help code
                                                        # its console output goes to the file now
                                                        help("print")
                                                        sys.stdout.close()
                                                        # reset stdout
                                                        sys.stdout = out





                                                        share|improve this answer

























                                                          up vote
                                                          0
                                                          down vote













                                                          Selected answer didn't work for me, so I did a little more searching and found something that worked on Daniweb. Credit goes to vegaseat. https://www.daniweb.com/programming/software-development/threads/20774/starting-python/8#post1306519



                                                          # simplified version of sending help() output to a file
                                                          import sys
                                                          # save present stdout
                                                          out = sys.stdout
                                                          fname = "help_print7.txt"
                                                          # set stdout to file handle
                                                          sys.stdout = open(fname, "w")
                                                          # run your help code
                                                          # its console output goes to the file now
                                                          help("print")
                                                          sys.stdout.close()
                                                          # reset stdout
                                                          sys.stdout = out





                                                          share|improve this answer























                                                            up vote
                                                            0
                                                            down vote










                                                            up vote
                                                            0
                                                            down vote









                                                            Selected answer didn't work for me, so I did a little more searching and found something that worked on Daniweb. Credit goes to vegaseat. https://www.daniweb.com/programming/software-development/threads/20774/starting-python/8#post1306519



                                                            # simplified version of sending help() output to a file
                                                            import sys
                                                            # save present stdout
                                                            out = sys.stdout
                                                            fname = "help_print7.txt"
                                                            # set stdout to file handle
                                                            sys.stdout = open(fname, "w")
                                                            # run your help code
                                                            # its console output goes to the file now
                                                            help("print")
                                                            sys.stdout.close()
                                                            # reset stdout
                                                            sys.stdout = out





                                                            share|improve this answer












                                                            Selected answer didn't work for me, so I did a little more searching and found something that worked on Daniweb. Credit goes to vegaseat. https://www.daniweb.com/programming/software-development/threads/20774/starting-python/8#post1306519



                                                            # simplified version of sending help() output to a file
                                                            import sys
                                                            # save present stdout
                                                            out = sys.stdout
                                                            fname = "help_print7.txt"
                                                            # set stdout to file handle
                                                            sys.stdout = open(fname, "w")
                                                            # run your help code
                                                            # its console output goes to the file now
                                                            help("print")
                                                            sys.stdout.close()
                                                            # reset stdout
                                                            sys.stdout = out






                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Nov 21 at 19:49









                                                            Matt

                                                            45




                                                            45






















                                                                up vote
                                                                0
                                                                down vote













                                                                The simplest way to do that is via using




                                                                sys module




                                                                it opens a data stream between the operation system and it's self , it grab the data from the help module then save it in external file



                                                                file="str.txt";file1="list.txt"
                                                                out=sys.stdout
                                                                sys.stdout=open('str_document','w')
                                                                help(str)
                                                                sys.stdout.close





                                                                share|improve this answer

























                                                                  up vote
                                                                  0
                                                                  down vote













                                                                  The simplest way to do that is via using




                                                                  sys module




                                                                  it opens a data stream between the operation system and it's self , it grab the data from the help module then save it in external file



                                                                  file="str.txt";file1="list.txt"
                                                                  out=sys.stdout
                                                                  sys.stdout=open('str_document','w')
                                                                  help(str)
                                                                  sys.stdout.close





                                                                  share|improve this answer























                                                                    up vote
                                                                    0
                                                                    down vote










                                                                    up vote
                                                                    0
                                                                    down vote









                                                                    The simplest way to do that is via using




                                                                    sys module




                                                                    it opens a data stream between the operation system and it's self , it grab the data from the help module then save it in external file



                                                                    file="str.txt";file1="list.txt"
                                                                    out=sys.stdout
                                                                    sys.stdout=open('str_document','w')
                                                                    help(str)
                                                                    sys.stdout.close





                                                                    share|improve this answer












                                                                    The simplest way to do that is via using




                                                                    sys module




                                                                    it opens a data stream between the operation system and it's self , it grab the data from the help module then save it in external file



                                                                    file="str.txt";file1="list.txt"
                                                                    out=sys.stdout
                                                                    sys.stdout=open('str_document','w')
                                                                    help(str)
                                                                    sys.stdout.close






                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Nov 28 at 16:57









                                                                    Nader Elsayed

                                                                    6615




                                                                    6615






























                                                                        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.





                                                                        Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                                        Please pay close attention to the following guidance:


                                                                        • 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%2f11265603%2fhow-do-i-export-the-output-of-pythons-built-in-help-function%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

                                                                        Berounka

                                                                        Sphinx de Gizeh

                                                                        Different font size/position of beamer's navigation symbols template's content depending on regular/plain...