我为家庭作业编写了以下内容,它在运行 Python 3 的 IDLE 和 Eclipse 中运行良好。
然而,我尝试使用新的第 1 行(我在此处找到的)从 TextMate 运行它,以将其指向 Mac 上的 Python 3。它似乎正在运行 Python 3 但返回错误。它说: EOFError: 读取一行时出现 EOF。它指的是下面的第 5 行。
有人知道为什么吗?
顺便说一句,这个 TextMate 问题不是家庭作业的一部分,所以我不想寻求家庭作业帮助。我只是想弄清楚如何将 TextMate 与 Python 3 一起使用。
#! /usr/local/bin/python3
#
# Tests user string against two conditions.
#
user_string = input("Enter a string that is all upper case and ends with a period: ")
if user_string.isupper() and user_string.endswith("."):
print("Your string met both conditions.")
else:
if user_string.isupper():
print("Your string does not end with a period.")
elif user_string.endswith("."):
print("Your string is not all upper.")
else:
print("Your string failed both conditions.")
您看到的问题与 Python 版本无关。问题是 TextMate 不会尝试重定向标准输入,因此,当您通过 TextMate 的 Python 包运行时Run Script
命令时,Python 程序会立即看到文件结束符。正如这里所解释的,TextMate 曾经对此比较感兴趣,但它使用的机制在 OS X 10.6 中不再起作用,因此该功能被禁用。
一种解决方案是使用Shift-Command-R Run Script in Terminal
TextMate 的 Python 包的命令。这会导致 TextMate 打开终端窗口并在其中运行脚本,您可以在其中输入输入。不幸的是,虽然 TextMate 确实尊重 shebang 线与正常Command-R Run Script command
,它似乎并没有这样做Run Script in Terminal
命令。您可以通过多种方式亲自验证这一点。尝试在 TextMate 中运行以下代码片段:
#! /usr/local/bin/python3
import sys
print(sys.executable)
为了解决这个问题,您可以设置TM_PYTHON
TextMate 中的环境变量。看答案在这里有关如何执行此操作的更多详细信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)