【问题标题】:Possible to write and access temporary file from within MyBinder Python environment?可以从 MyBinder Python 环境中写入和访问临时文件吗?
【发布时间】:2019-04-16 00:22:17
【问题描述】:

我需要编写一个 STL 文件,然后在一个脚本中解析它,所有这些都在一个可共享的 python 笔记本的 mybinder.org 实例中。这可能吗?

【问题讨论】:

    标签: python docker jupyter-notebook


    【解决方案1】:

    我只是自己尝试了一下,所有需要做的。 可能是糟糕的做法,但很实用。

    import os
    cwd = os.getcwd() # gets directory of docker environment
    sys.path.append(cwd)
    
    testfile = cwd + '/testfile.txt'
    with open(testfile, 'w') as tf:
        tf.write('Hello World')
    
    with open(testfile, 'r') as tf2:
        print(tf2.read())
    

    【讨论】:

      猜你喜欢
      • 2017-02-20
      • 2015-09-04
      • 2023-03-10
      • 2018-12-07
      • 2021-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多