是否可以从MyBinder Python环境中写入和访问临时文件?

2024-04-29 22:22:46 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: 文件实例org脚本笔记本stlmybinder
1条回答
网友
1楼 · 发布于 2024-04-29 22:22:46

我只是自己试了一下,所有这些都需要做。 可能是可怕的做法,但功能

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())

相关问题 更多 >