我与Python 3.6.2创建我的电脑(视窗10)上python脚本,它就像一个魅力:脚本在Windows上运行,但不能在Linux上(语法错误)
for i in range(101):
time.sleep(0.015)
print('Starting ..... [%d%%]\r'%i, end="")
else :
print('\n Ready.')
我最近买了覆盆子PI上raspbian运行与Python 3.4.2,当我尝试从我得到了一个错误的命令完全相同的脚本:
print('Starting ..... [%d%%]\r'%i, end="")
^
Syntax Error: invalid Syntax (The error seems to be the equal sign)
任何想法?也许Python版本?也许别的东西?
编辑:
事实上,@Steven Rumbalski是正确的。 Raspbian automaticaly安装Python的两个版本:2.7.9和3.4.2 所以我只需要把“python3 myscript.py”而不是“python myscript.py”(或者@Toandd说:使用shebang行)谢谢你非常乐意帮忙。
这就是你用Python 2.7得到的错误,其中'print'是一个语句而不是函数。我敢打赌,如果你去命令行并运行'python -V',你会显示Python 2.7。您的树莓派可能有Python 2.7和Python 3.4。有时python 3被区分为python3,而Python 2只是python,但我不知道raspberry pi的收敛是什么。 –
如果你发现你已经安装了Python 2和Python 3,你可能会在Raspberry Pi Stack Exchange站点上发现这个问题很有帮助:[我想在Python的版本2和3之间切换。两者都已安装](https://raspberrypi.stackexchange.com/questions/42813/i-want-to-switch-between-versions-2-3-of-python-both-are-installed)。 –