如何在QT控制台python中保存代码历史?

2024-04-25 20:04:42 发布

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

我刚从R切换到Python,发现jupyterqt控制台非常方便,并且有助于逐行运行代码。在

但我有一个问题:如何保存已经输入的代码?我的意思是,就像Rstudio一样,左上角是代码编辑器,左下角是控制台窗口。所以我可以得到我的代码的全貌并逐行调试它们。在

我试过Spyder(类似Rstudio),但它在自动完成方面有一些问题。Qt控制台更好。有没有一种方法可以将文本编辑器和qt控制台组合到一个单独的IDE中?在

谢谢!在


Tags: 方法代码编辑器qtide文本编辑spyderrstudio
1条回答
网友
1楼 · 发布于 2024-04-25 20:04:42

从jupyter qtconsole,您可以使用%save魔术来保存您的工作。它比我想要的更麻烦,因为您必须指定要保存的输入单元格,但仍然非常方便。在

例如,要将输入单元格2到7保存到名为MyCommands.py的文件中,只需键入

%save MyCommands.py 2-7

将文件保存在当前工作目录中。如果文件已经存在,它甚至会警告你并要求确认。在

有关更多信息,请使用jupyter极其有用的内置帮助功能,方法是在需要帮助的项目后添加问号。在

^{pr2}$

它打印docstring

Docstring: Save a set of lines or a macro to a given filename.

Usage: %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...

Options:

-r: use 'raw' input. By default, the 'processed' history is used,
so that magics are loaded in their transformed version to valid
Python. If this option is given, the raw input as typed as the
command line is used instead. -f: force overwrite. If file exists, %save will prompt for overwrite unless -f is given.

-a: append to the file instead of overwriting it.

This function uses the same syntax as %history for input ranges, then saves the lines to the filename you specify.

It adds a '.py' extension to the file if you don't do so yourself, and it asks for confirmation before overwriting existing files.

If -r option is used, the default extension is .ipy. File:
~/anaconda3/lib/python3.5/site-packages/IPython/core/magics/code.py

请注意,您可以使用问号来研究带有docstring的任何函数或对象(即enumerate?range?)。在

相关问题 更多 >