如何在树莓派上修复“SyntaxError: invalid syntax”错误?

4
我在Windows上编写了代码,编译并正确运行,但在树莓派上却失败了。我编写了一些简单的测试代码,以查看是否输出相同的错误。
a = input('this is a test string to split at space \n').split()

print(a)

我在15:00打字(这是更大项目所需的数据点),然后遇到了这个错误。

15:00
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    a = input('this is a test string to split at : \n').split(':')
   File "<string>", line 1
    15:00
      ^
 SyntaxError: invalid syntax

有人在Discord上要求我尝试15:00,结果收到了以下消息:

15 00
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    a = input('this is a test string to split at : \n').split(':')
  File "<string>", line 1
    15 00
        ^
SyntaxError: unexpected EOF while parsing
1个回答

1
你可能在Windows和树莓派上运行不同版本的Python。
感谢这个答案

注意:这仅适用于Python 2。对于Python 3,raw_input()变为input(),而Python 2中的input()已被移除。

参考资料

a = raw_input('this is a test string to split at space \n').split(':')

print(a)

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接