【问题标题】:Export python file to PDF without code i.e only with outputs将python文件导出为PDF,无需代码,即仅输出
【发布时间】:2019-08-27 16:11:36
【问题描述】:

我一直在尝试找到一种将我的 python 文件转换为 pdf 的方法。 我找到了 Latex、pyweave 和其他人,但我无法理解如何不在我的 pdf 中包含输入代码。另外,如何使用pyweave? 我的 pdf 不应该包含任何代码,只包含输出。 如何实现?

在 jupyter 中,我们有带有 --no 输入标志的 nbconvert 工具。 在普通的python文件中怎么样?

【问题讨论】:

    标签: python pandas jupyter-notebook latex pdflatex


    【解决方案1】:

    python 包可能会有所帮助:

    \documentclass{article}
    
    \usepackage{python}
    
    \begin{document}
    
    \begin{python}
    print("42")
    \end{python}
    
    \end{document}
    

    (需要在编译时启用 shell-escape)

    【讨论】:

    • 这是哪个包?
    • @rojoka 这个包叫python
    【解决方案2】:

    一种可能的方式:https://discourse.mcneel.com/t/saving-the-python-output-as-textfile/14987/2指的是上面的帖子

    1.创建一个空的python字符串

    output_string = ''
    

    2.开始将所有可能的结果添加到 output_string

    # If you want perform print(some_object), add it to the string
    output_string = output_string + str(some_object) + "\n"
    

    3. 使用任何技术将字符串转换为 pdf 文件

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-05
    相关资源
    最近更新 更多