快速说明:python,终端“未找到打印命令”
使用终端运行 textwrangler 编写的 python 脚本已有大约 18 个月了。决定考虑迁移到 IDE 的可能性,因此下载了几个试用版本。刚刚下载了 BBEedit,突然在执行来自 BBedit 或 Textwrangler 的脚本时遇到问题。以下代码:
print "Please work"
for i in range(50):
print i
产生以下错误消息:
/Users/paulpatterson/Documents/Python/Scripts/t.py: line 1: print: command not found
/Users/paulpatterson/Documents/Python/Scripts/t.py: line 3: syntax error near unexpected token `('
/Users/paulpatterson/Documents/Python/Scripts/t.py: line 3: `for i in range(50):'
某些文件仍然可以正常工作,但我正在努力找出为什么其他文件现在不能 - 甚至不确定 BBedit 下载是否导致了该问题。 有人可以帮忙吗?
Been using terminal to run python scripts written in textwrangler for about 18 months. Decided to look at possibility of moving to an IDE so downloaded a couple of trial versions. Just downloaded BBEedit and suddenly having problems executing script, either from BBedit or Textwrangler. The following code:
print "Please work"
for i in range(50):
print i
yields the following error message:
/Users/paulpatterson/Documents/Python/Scripts/t.py: line 1: print: command not found
/Users/paulpatterson/Documents/Python/Scripts/t.py: line 3: syntax error near unexpected token `('
/Users/paulpatterson/Documents/Python/Scripts/t.py: line 3: `for i in range(50):'
Some files still work okay, but I'm struggling to figure out why others now aren't -
not even sure if BBedit download has caused the problem.
Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将其放在
脚本的顶部。该程序尝试像 shell 脚本一样执行它,而不是通过 python 运行它。
Try putting
at the top of the script. The program is trying to execute it like a shell script instead of running it through python.
它将脚本作为 shell 脚本运行,而不是 Python 脚本。
It's running the script as a shell script, not a Python script.
另外,请注意,当您转换为 Python 3 时,这种形式的 print(print-as-command)将更改为 print-as-a-function。因此:
必须更改为:
Also, be aware that this form of print (print-as-command) is changing to print-as-a-function when you convert to Python 3. So:
will have to be changed to: