我想将已经缩进的Python代码/整个函数和类复制到IPython中。每次我尝试缩进都会出错,并得到以下错误信息:
IndentationError: unindent does not match any outer indentation level (<ipython-input-23-354f8c8be51b>, line 12)
If you want to paste code into IPython, try the %paste and %cpaste magic functions.
发布于 2015-09-06 00:47:19
%paste
需要Tkinter
。如果你在ubuntu中,你可以通过以下方式安装它
sudo apt-get install python-tk
如果您使用的是Python3
sudo apt-get install python3-tk
然后重新启动ipython并使用%paste
从剪贴板粘贴。
发布于 2016-02-22 16:26:30
其中一个有用的答案在评论中丢失了,所以我想在添加另一个有用的IPython魔术函数的参考的同时重申一下。
首先重申@EOL所说的,解决OP问题的一种方法是关闭自动缩进,方法是首先运行%autoindent
并进行粘贴(当然,如果您使用的是%paste
,则不需要)。
现在,为了向这里已有的内容添加更多信息,IPython中一个更有用的模式是%doctest_mode
,它允许您从文档字符串中复制粘贴示例和测试片段。这对于执行交互式python会话输出也很有用,您可以在文档和在线论坛中找到这些输出,而不必首先去掉提示字符串。
发布于 2017-01-26 14:14:22
适用于使用Python 3的ubuntu用户。
python-tk
是针对Python2的。
要使%paste
在Python3上工作,请安装python3-tk
包:
sudo apt-get install python3-tk
https://stackoverflow.com/questions/10886946
复制相似问题