简体   繁体   English

我应该保存哪种格式的python脚本输出?

[英]Which format should I save my python script output?

I have an executable (converted to exe from python using py2exe) that outputs lists of numbers that could be from 0-50K lines long or a little bit more. 我有一个可执行文件(使用py2exe从python转换为exe),输出的数字列表的长度可能为0-50K行或更多。 While developing, I just saved them to a TXT file using simple f.write. 在开发过程中,我只是使用简单的f.write将它们保存到TXT文件中。 The person wants to print this output on paper! 该人想将此输出打印在纸上! (don't ask why lol) (不要问为什么大声笑)

So, I'm wondering if I can output it to something like HTML? 因此,我想知道是否可以将其输出为类似HTML的内容? XML? XML? Something that could display tables of 50K lines and maybe 3 columns and that would also run in any PC without additional programs? 是否可以显示5万行表格和3列表格,是否还可以在任何PC上运行而无需其他程序? Suggestions? 有什么建议吗?

EDIT: 编辑:
Regarding CSV: 关于CSV:
In most situations the best way in my opinion would be to make a CSV. 在大多数情况下,我认为最好的方法是制作CSV。 I'm not opposing it in anyway, rather I think others might find Lott's answer useful for their cases. 我无论如何都不反对,而是我认为其他人可能会发现洛特的回答对他们的案子有用。 Sorry I didn't explain it that well in my question as far as my constraints go. 抱歉,就我的约束而言,我在问题中的解释不够好。
My constraints are: the user doesn't have an office suite, no python installed. 我的约束是:用户没有办公套件,没有安装python。 Just think of a PC that has the bare minimum after a clean windows xp/vista installation, maybe Internet Explorer 7 or 8. This PC has to be able to open my output file and allow for reasonable viewing, searching, and printing. 试想一下一台干净的Windows xp / vista安装后的最低配置的PC,也许是Internet Explorer 7或8。该PC必须能够打开我的输出文件,并允许合理的查看,搜索和打印。

CSV. CSV。

http://docs.python.org/library/csv.html http://docs.python.org/library/csv.html

http://en.wikipedia.org/wiki/Comma-separated_values http://en.wikipedia.org/wiki/Comma-separated_values

They can load a spreadsheet and print anything they want. 他们可以加载电子表格并打印所需的任何内容。

如果您无法在计算机上安装任何软件,则最好是将HTML文件与<table>中的数据一起输出,以便用户可以在IE中查看/搜索/打印。

You could use LaTeX to produce a PDF, maybe? 您可以使用LaTeX生成PDF,也许吗? But why exactly isn't a text file good enough? 但是,为什么文本文件不够好呢?

You can produce a PDF using Reportlab . 您可以使用Reportlab生成PDF。 After all if you really want full control of the printed output, there's nothing that beats PDF. 毕竟,如果您真的想完全控制打印输出,那么没有比PDF更胜一筹的了。

Does 50k lines make too large a file? 5万行会使文件太大吗? If not, just continue writing text files. 如果不是,则继续写入文本文件。 Otherwise an easy solution would be to continue spitting out text files and compress them, eg with zip. 否则,一个简单的解决方案是继续吐出文本文件并压缩它们,例如使用zip。 You could use the zipfile library in Python. 您可以在Python中使用zipfile库。 Most computers have no trouble reading zip files. 大多数计算机都可以轻松读取zip文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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