快速说明:python,终端“未找到打印命令”

发布于 2024-10-05 08:50:19 字数 606 浏览 9 评论 0原文

使用终端运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

荆棘i 2024-10-12 08:50:23

尝试将其放在

#!/usr/bin/env python

脚本的顶部。该程序尝试像 shell 脚本一样执行它,而不是通过 python 运行它。

Try putting

#!/usr/bin/env python

at the top of the script. The program is trying to execute it like a shell script instead of running it through python.

清风挽心 2024-10-12 08:50:23

它将脚本作为 shell 脚本运行,而不是 Python 脚本。

It's running the script as a shell script, not a Python script.

一个人的旅程 2024-10-12 08:50:23

另外,请注意,当您转换为 Python 3 时,这种形式的 print(print-as-command)将更改为 print-as-a-function。因此:

print "please work"

必须更改为:

print ("please work")

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:

print "please work"

will have to be changed to:

print ("please work")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文