1

I have a task that requires me to encapsulate multiple functions, each with one or more outputs.At present, the function has been encapsulated and the calling program has been written, which can output the result of the function to the computer screen.How to call the results of the function output to a txt file, and can be written in the original format (the line when the line) to txt.

The function is called successfully and outputs the results to the computer screen.

This is the part of the code that calls the function and a simple function.

        if len_1[3] == '1':
            import DecodeField_015
            Item015 = list_1[i]
            DecodeField_015.DecodeField015(Item015)
            i = i + 1


        if len_1[4] == '1':
            import DecodeField_071
            Item071 = list_1[i]
            DecodeField_071.DecodeField071(Item071)
            i = i + 3

        def DecodeField015(Input):
         str1 = 0
         print('\nData Item I021/015, Service Identification')
         I015 = '{:08b}'.format(Input)
         print('bits 8/1,Service Identification: ' + I015)
         return str1

This is the simplest example of a function. There are more than 40 functions like this.How to write the output of more than 40 functions into the txt file in order of function call.

An Chenhui
  • 11
  • 4
  • Just to clarify, when you talk about the "output" of the functions, you are referring to how `print` is handled? Normally I would assume "output" would mean the `return` value, but you talk at the beginning about what is "outputted" to the computer screen, so it's not clear to me which you're asking about. – Reid Ballard May 09 '19 at 15:59
  • My goal is to write all of the "print" in the function into a txt text. – An Chenhui May 10 '19 at 03:16
  • What I want is to write the contents of the current function [print] into txt instead of [print] it out. – An Chenhui May 10 '19 at 03:22
  • Possible duplicate of [How to redirect 'print' output to a file using python?](https://stackoverflow.com/questions/7152762/how-to-redirect-print-output-to-a-file-using-python) – Reid Ballard May 10 '19 at 11:58

0 Answers0