如何在执行Python函数时将终端上的所有输出打印到PDF?

huangapple go评论54阅读模式
英文:

How to print all output in terminal to pdf when executing function in python?

问题

我有一个执行加法、减法、乘法和除法的函数。

def calculator(x, y):
    print("Summation between", x, " & ", y, "is:", x + y)
    print("Subtraction between", x, " & ", y, "is:", x - y)
    print("Division between", x, " & ", y, "is:", x / y)
    print("Multiplication between", x, " & ", y, "is:", x * y)

调用calculator函数后,从终端获取输出如下:

Summation between 5  &  6 is:  11
Subtraction between 5  &  6 is:  -1
Division between 5  &  6 is:  0.8333333333333334
Multiplication between 5  &  6 is:  30

我想将终端输出的所有值转换成PDF文件。感谢帮助!

英文:

For example, I have a function that performs addition, subtraction, multiplication and division.

def calculator(x,y):
    print("Summation between", x, " & ",y, "is: ", x + y)
    print("Subtraction between", x, " & ", y, "is: ", x - y)
    print("Division between", x, " & ", y, "is: ", x / y)
    print("Multiplication between", x, " & ", y, "is: ", x * y)

after calling the calculator function I get the output from the terminal, and output is:

Summation between 5  &  6 is:  11
Subtraction between 5  &  6 is:  -1
Division between 5  &  6 is:  0.8333333333333334
Multiplication between 5  &  6 is:  30

I want to get all output value from terminal and convert to pdf file. Thank for help me!

答案1

得分: 1

Looks similar to the question here, with many answers for reference.
https://unix.stackexchange.com/questions/17406/how-to-convert-txt-to-pdf

英文:

Looks similar to the question here, with many answers for reference.
https://unix.stackexchange.com/questions/17406/how-to-convert-txt-to-pdf

huangapple
  • 本文由 发表于 2023年3月23日 11:23:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75819000.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定