A method to extract the output content of the print function of a custom script

By replacing the print closure function provided by the Python native print function for the platform server, the problem of not being able to output intermediate process information in custom Python scripts is solved, and the collection and display of the output content of the custom script print is realized, and users can perform effective programming work.

CN114443179BActive Publication Date: 2025-04-04SHANGHAI GUANQIN INFORMATION TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210058050.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-19
Publication Date
2025-04-04
Estimated Expiration
2042-01-19

AI Technical Summary

Technical Problem

In systems that support custom Python scripts, users cannot output information about intermediate processes when writing and debugging scripts, which affects programming work.

Method used

By replacing the Python native print function with the print closure function provided by the platform server, and outputting the output content to the user script context storage object printmsg, the collection and display of the output content of the custom script print function is realized.

Benefits of technology

Maintaining the print function call method consistent with the native script in a custom script, the platform can effectively collect and display the print output content to help users design the program.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114443179B_ABST
    Figure CN114443179B_ABST
Patent Text Reader

Abstract

The present invention provides a method for extracting the output content of a custom script print function, comprising: editing the script code on a platform Web page, selecting to execute the script, and sending a script execution request to a platform server; the platform server creates a script context and initializes an output storage object; the native print function is replaced with a custom print function, and is injected into the script context; the replaced custom print function is called in the script, and the output content is written into the output storage object; the platform server returns the content in the output storage object to the front end through an HTTP response, and the front end displays the output content in a Web interface. The method of the present invention can call the print function in the custom script in the same way as the native script, and the platform responsible for executing the custom script can collect the content printed in the custom script, and will not be confused with the print in the main program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer program design, and in particular to a method for extracting output content of a custom script print function. Background Art

[0002] For systems that support custom Python scripts, when users are writing and debugging custom Python scripts, they need to output some information during program execution to help with programming.

[0003] Generally speaking, platforms that support executing user-defined scripts in the main program will only display the final return value or error message of the function for the executed custom script, and cannot output information about the intermediate process, which cannot help program design work well. Summary of the invention

[0004] In view of this, the purpose of the present invention is to enable a system that executes user-defined Python scripts to collect the content output by the print function when running the customized script; and to execute the script context feature to realize the function of collecting the output content when using the print function in the user-defined script.

[0005] The implementation core of the method of the present invention is to replace the Python native print function with the print closure function provided by the platform server, and the print closure function provided by the platform server outputs the output content to the storage object printmsg in the user script context.

[0006] The present invention provides a method for extracting output content of a custom script print function, comprising the following steps:

[0007] a1. Edit the script code on the platform web page, select the execution script, and send a script execution request to the platform server through the platform web front end;

[0008] a2. After receiving the script execution request, the platform server creates a script context and initializes the output storage object;

[0009] a3. Replace the native print function with a custom print function, and inject the replaced custom print function into the script context;

[0010] a4. When the print function is called in the script, the replaced custom print function is actually called, and the replaced custom print function writes the output content into the output storage object;

[0011] a5. After the script is executed, the platform server returns the content in the output storage object to the front end through HTTP response. After receiving the HTTP response, the front end displays the output content in the Web interface.

[0012] Furthermore, the content of the script execution request in step a1 includes the script ID to be executed and the function name to be executed.

[0013] Furthermore, the method for creating a script context in step a2 includes:

[0014] After receiving the script execution request, the platform server calls the initContext function to create a script context, and adds objects and functions for outputting and collecting custom script outputs.

[0015] Furthermore, the output storage object of step a2 is printmsg, which is a string IO object used to store the output content of the print function.

[0016] Furthermore, the method of replacing the native print function with the custom print function in step a3 includes:

[0017] Create a closure function print. Except for the file parameter, the other parameters of the closure function print are the same as those of the native print function. The parameter file is fixed to the printmsg. Pass the user input parameters and the file parameter to the Python native print function to collect the print content.

[0018] Add the closure function print to the script context and overwrite the native print function (i.e. builtins.print).

[0019] Furthermore, the method of calling the print function in the script of step a4 includes:

[0020] The script context is loaded into a custom script, and the closure function print is called in the custom script.

[0021] Furthermore, the method of writing the output content into the output storage object in step a4 includes:

[0022] The closure function print outputs the content to the storage object printmsg in the script context;

[0023] The output content will be collected because the parameter file is fixed to the printmsg.

[0024] Furthermore, the method of returning the content in the output storage object to the front end in step a5 includes:

[0025] The platform server calls the getScriptMessage function getScriptMessage(context) to retrieve the content of printmsg in the script context;

[0026] The platform server responds to the HTTP request and returns the content of printmsg to the platform web front end through the HTTP response.

[0027] Furthermore, the method of displaying the output content in the Web interface in step a5 includes:

[0028] After receiving the HTTP response, the platform Web front end displays the content of the printmsg contained therein on the Web page for users to view.

[0029] The present invention also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps of the method for extracting the output content of the print function of the custom script as described above are implemented.

[0030] The present invention also provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps of the method for extracting the output content of the print function of a custom script as described above are implemented.

[0031] Compared with the prior art, the present invention has the following beneficial effects:

[0032] The method of the present invention can call the print function in the custom script in the same way as the native script, and the platform responsible for executing the custom script can collect the content printed in the custom script without being confused with the print in the main program. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] Various other advantages and benefits will become apparent to users of ordinary skill in the art by reading the following detailed description of the preferred embodiment.The drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention.

[0034] In the attached picture:

[0035] Figure 1 It is a flow chart of a method for extracting output content of a custom script print function of the present invention;

[0036] Figure 2It is a diagram of the structure of a computer device according to an embodiment of the present invention;

[0037] Figure 3 It is a flowchart of a process for extracting output contents of a custom script print function according to an embodiment of the present invention;

[0038] Figure 4 This is a diagram showing the interface of the print output of the embodiment of the present invention. DETAILED DESCRIPTION

[0039] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0040] The terms used in this disclosure are for the purpose of describing specific embodiments only and are not intended to limit the disclosure. The singular forms of "a", "said" and "the" used in this disclosure and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0041] It should be understood that although the terms first, second, and third may be used to describe various signals in the present disclosure, these signals should not be limited to these terms. These terms are only used to distinguish signals of the same type from each other. For example, without departing from the scope of the present disclosure, the first signal may also be referred to as the second signal, and similarly, the second signal may also be referred to as the first signal. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0042] The core of the implementation method of the embodiment of the present invention is to replace the Python native print function with the closure function print provided by the platform server, and the closure function print provided by the platform server outputs the output content to the storage object printmsg in the user script context.

[0043] The embodiment of the present invention provides a method for extracting the output content of the print function of a custom script, see Figure 1 As shown, the following steps are included:

[0044] a1. Edit the script code on the platform web page, select execute script, and send a script execution request to the platform server through the platform web front end;

[0045] a2. After receiving the script execution request, the platform server creates a script context and initializes the output storage object;

[0046] a3. Replace the native print function with a custom print function, and inject the replaced custom print function into the script context;

[0047] a4. When the print function is called in the script, the replaced custom print function is actually called, and the replaced custom print function writes the output content into the output storage object;

[0048] a5. After the script is executed, the platform server returns the content in the output storage object to the front end through HTTP response. After receiving the HTTP response, the front end displays the output content in the Web interface.

[0049] The content of the script execution request in step a1 includes the script ID to be executed and the function name to be executed.

[0050] The method for creating a script context in step a2 includes:

[0051] After receiving the script execution request, the platform server calls the initContext function to create a script context, and adds objects and functions for outputting and collecting custom script outputs.

[0052] The output storage object of step a2 is printmsg, which is a string IO object used to store the output content of the print function.

[0053] The method of replacing the native print function with the custom print function in step a3 includes:

[0054] Create a closure function print. Except for the file parameter, the other parameters of the closure function print are the same as those of the native print function. The parameter file is fixed to the printmsg. Pass the user input parameters and the file parameter to the Python native print function to collect the print content.

[0055] Add the closure function print to the script context and overwrite the native print function (i.e. builtins.print).

[0056] The method of calling the print function in the custom script of step a4 includes:

[0057] The script context is loaded with the custom script; and the closure function print is called in the custom script.

[0058] The method of writing the output content into the output storage object in step a4 comprises:

[0059] The closure function print outputs the content to the storage object printmsg in the script context;

[0060] The output content will be collected because the parameter file is fixed to the printmsg.

[0061] The method of returning the content in the output storage object to the front end in step a5 includes:

[0062] The platform server calls the getScriptMessage function getScriptMessage(context) to retrieve the content of printmsg in the script context;

[0063] The platform server responds to the HTTP request and returns the content of printmsg to the platform web front end through the HTTP response.

[0064] The method of displaying the output content in the Web interface in step a5 includes:

[0065] After receiving the HTTP response, the platform Web front end displays the printmsg content contained in it on the Web page for users to view. Figure 4 As shown, the interface display of the print output of the embodiment of the present invention is shown.

[0066] See also Figure 3 As shown, it is a schematic diagram of the processing flow of extracting the output content of the print function of the custom script according to an embodiment of the present invention.

[0067] The method of the embodiment of the present invention can call the print function in the custom script in the same way as the native script. The platform responsible for executing the custom script can collect the content printed in the custom script and will not be confused with the print in the main program.

[0068] The embodiment of the present invention further provides a computer device, Figure 2 is a schematic diagram of the structure of a computer device provided by an embodiment of the present invention; see the accompanying drawings Figure 2As shown, the computer device includes: an input device 23, an output device 24, a memory 22 and a processor 21; the memory 22 is used to store one or more programs; when the one or more programs are executed by the one or more processors 21, the one or more processors 21 implement the method for extracting the output content of the custom script print function provided in the above embodiment; wherein the input device 23, the output device 24, the memory 22 and the processor 21 can be connected by a bus or other means, Figure 2 The example of connecting through bus is taken in the following.

[0069] The memory 22 is a readable and writable storage medium of a computing device, which can be used to store software programs and computer executable programs, such as program instructions corresponding to the method for extracting the output content of the print function of a custom script described in an embodiment of the present invention; the memory 22 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system and at least one application required for a function; the data storage area can store data created according to the use of the device, etc.; in addition, the memory 22 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device; in some instances, the memory 22 can further include a memory remotely arranged relative to the processor 21, and these remote memories can be connected to the device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0070] The input device 23 may be used to receive input digital or character information, and to generate key signal input related to user settings and function control of the device; the output device 24 may include a display device such as a display screen.

[0071] The processor 21 executes various functional applications and data processing of the device by running the software programs, instructions and modules stored in the memory 22, that is, implements the above-mentioned method of extracting the output content of the custom script print function.

[0072] The computer device provided above can be used to execute the method for extracting the output content of the print function of the custom script provided in the above embodiment, and has corresponding functions and beneficial effects.

[0073] The embodiment of the present invention also provides a storage medium containing computer executable instructions, which are used to perform the method of extracting the output content of the custom script print function provided in the above embodiment when executed by a computer processor. The storage medium is any of various types of memory devices or storage devices, and the storage medium includes: installation media, such as CD-ROM, floppy disk or tape device; computer system memory or random access memory, such as DRAM, DDRRAM, SRAM, EDO RAM, Rambus RAM, etc.; non-volatile memory, such as flash memory, magnetic media (such as hard disk or optical storage); registers or other similar types of memory elements, etc.; the storage medium may also include other types of memory or a combination thereof; in addition, the storage medium may be located in the first computer system in which the program is executed, or may be located in a different second computer system, the second computer system is connected to the first computer system via a network (such as the Internet); the second computer system may provide program instructions to the first computer for execution. The storage medium includes two or more storage media that can reside in different locations (for example, in different computer systems connected via a network). The storage medium can store program instructions (for example, specifically implemented as a computer program) that can be executed by one or more processors.

[0074] Of course, the storage medium containing computer executable instructions provided in an embodiment of the present invention is not limited to the method for extracting the output content of the custom script print function as described in the above embodiment, and can also execute related operations in the method for extracting the output content of the custom script print function provided in any embodiment of the present invention.

[0075] So far, the technical solutions of the present invention have been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for users skilled in the art to understand that the protection scope of the present invention is obviously not limited to these specific embodiments. Without departing from the principle of the present invention, users skilled in the art can make the same changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present invention.

[0076] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For technical users in the field, the present invention may have various modifications and changes. Any modification, replacement, and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for extracting the output content of a custom script print function, characterized in that: The following steps are involved: a1. Edit the script code on the platform web page, select execute script, and send a script execution request to the platform server through the platform web front end; a2. After receiving the script execution request, the platform server creates a script context and initializes the output storage object; a3. Replace the native print function with a custom print function, and inject the replaced custom print function into the script context; a4. When the print function is called in the script, the replaced custom print function is actually called, and the replaced custom print function writes the output content into the output storage object; a5. After the script is executed, the platform server returns the content in the output storage object to the front end through HTTP response. After receiving the HTTP response, the front end displays the output content in the Web interface. The method of replacing the native print function with the custom print function in step a3 includes: Create a closure function print, pass the user input parameters and file parameters to the Python native print function, and collect the print content; Add the closure function print to the script context and overwrite the native print function; Wherein, the output storage object of step a2 is printmsg, which is used to store the output content of the print function; Among them, except for the file parameter, the other parameters of the closure function print are the same as those of the native print function, and the parameter file is fixed to the printmsg; The method of returning the content in the output storage object to the front end in step a5 includes: The platform server calls the getScriptMessage function, the parameters of which include context, and retrieves the content of printmsg in the script context; The platform server responds to the HTTP request and returns the content of printmsg to the platform web front end through HTTP response; The method of displaying the output content in the Web interface in step a5 includes: After receiving the HTTP response, the platform Web front end displays the content of the printmsg contained therein on the Web page for users to view.

2. The method for extracting the output content of the custom script print function according to claim 1, characterized in that: The content of the script execution request in step a1 includes the script ID to be executed and the function name to be executed.

3. The method for extracting the output content of the custom script print function according to claim 1, characterized in that: The method for creating a script context in step a2 includes: After receiving the script execution request, the platform server calls the initContext function to create a script context, and adds objects and functions for outputting and collecting custom script outputs.

4. The method for extracting the output content of the custom script print function according to claim 1, characterized in that: The method of calling the print function in the script of step a4 includes: The script context is loaded into a custom script, and the closure function print is called in the custom script.

5. The method for extracting the output content of the custom script print function according to claim 1, characterized in that: The method of writing the output content into the output storage object in step a4 comprises: The closure function print outputs the content to the storage object printmsg in the script context.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method for extracting the output content of the print function of a custom script according to any one of claims 1 to 5 are implemented.

7. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the method for extracting the output content of the print function of the custom script as described in any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Data processing method and device

    CN113312053A