2024-04-26 00:53:00 发布
网友
我正在使用一个库,它希望我以文件名的形式传递数据。然后它将打开该文件并读取数据。我有一个字符串中的数据,我不想把它写到一个文件中(因为我不想在以后删除它)。你知道吗
有没有一种方法可以将字符串转换为流并生成一个文件名,以便我的库打开我的流并访问字符串的内容?你知道吗
import tempfile fh = tempfile.NamedTemporaryFile() # this creates an actual file in the temp directory fh.write(my_string) print fh.name call_other_thing(fh.name) fh.close() # file is now deleted
相关问题 更多 >
编程相关推荐