gpt4 book ai didi

python - 是否可以在 IPython Notebook 的 %%writefile 魔术命令中写入变量的值?

转载 作者:太空狗 更新时间:2023-10-30 00:19:31 25 4
gpt4 key购买 nike

我希望能够使用变量在 IPython Notebook 中输出一些文本。我可以使用 %%writefile 命令从 IPython Notebook 中写入文件。我还可以使用变量来使用 $varaible_name 命名文件。

file_name = "file.out"
some_variable = "text"

新建单元格

%%writefile $file_name
????some_varaible #<-what command goes here

因此输出文件(名为“file.out”)如下所示:

文字

最佳答案

现在可以使用以下命令::

%store varname > filename.txt

More about %store

关于python - 是否可以在 IPython Notebook 的 %%writefile 魔术命令中写入变量的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26385041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com