简体   繁体   中英

Converting Python output to PDF

I was working on a mini project and it involves me writing code to determine the mean, median, mode and range as the first stage (which I was successfully able to do). The second and final stage is to convert the output into a PDF file. I do not know how to do this, and hence, this was the code I could successfully run. Other than the converter, I had no problems using this code to find the output of my mean, median, mode and range.

For working out the mean:

 def mean(numbers): return float(sum(numbers)) / max(len(numbers), 1) 

For working out the median:

 def median(lst): lst = sorted(lst) if len(lst) < 1: return None if len(lst) %2 == 1: return lst[((len(lst)+1)/2)-1] else: return float(sum(lst[(len(lst)/2)-1:(len(lst)/2+1)]))/2.0 

For working out the mode:

 def mode(array): most = max(list(map(array.count, array))) return list(set(filter(lambda x: array.count(x) == most, array))) 

For working out the range:

 def getrange(val_list): min_val = min(val_list) max_val = max(val_list) return (max_val - min_val) 

This package looks pretty good:

https://pypi.python.org/pypi/pdfdocument

您可以尝试pyPDF ,尤其是PdfFileWriter()类来执行相同的操作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM