如何打印数据框?

How to paper print a dataframe?

所有在线搜索都涉及在控制台中打印 df。 python 是否能够直接打印 df(无需将其保存为 windows 中的文件)?

澄清 - 它不应保存为 pdf/excel/any 其他文件。我们可以直接打印(打印到纸上)数据框吗?

就我的探索而言,我认为我们无法直接从 Python 打印任何内容(字符串/图形/等)。我们可能总是必须通过文件来完成 (doc/excel/pdf)。如有不妥请指正

您可以使用 win32print 模块。

请先阅读以下内容documents

Applications that print create a printer device context (DC). When an application creates a printer DC, the spooler performs necessary tasks such as determining the location of the required printer driver and then loading that driver. The print spooler also determines the data type used to record the print job.

The print spooler supports the following data types:

  • Enhanced metafile (EMF).
  • ASCII text.
  • Raw data, which includes printer data types such as PostScript, PCL, and custom data types.

Custom data types can be added to the spooler by installing additional printer drivers and print processors. A print job is a document stored internally and encoded by using one of the supported data types, and a print job may contain one or more pages of output.

The spooler deletes these files when the job has successfully printed.

确实可以直接打印作业而不将它们保存为文件,因为后台处理程序会在打印后直接删除这些文件。

相关: