相关疑难解决方法(0)

复制粘贴到Python交互式解释器和缩进

这段代码,test.py:

if 1:
   print "foo"
print "bar"
Run Code Online (Sandbox Code Playgroud)

可以使用execfile("test.py")或成功执行python test.py,但是当一个人尝试将其复制粘贴到python解释器中时:

File "<stdin>", line 3
print "bar"
        ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

为什么会这样?可以通过配置解释器以便成功读取复制粘贴的文本吗?我想这可能会影响口译员的输入,但这对我来说没问题.

python copy-paste indentation

15
推荐指数
5
解决办法
3万
查看次数

标签 统计

copy-paste ×1

indentation ×1

python ×1