我正在使用Python 3.4在Windows 8.1中运行此脚本。 这是我的脚本的一部分,我相信这是造成问题:Python 3脚本无法在Python 3.4中正常运行,但Python 2脚本能正常工作
if __name__ == '__main__':
import sys
print("Enter a sentence: ",end="")
sen = sys.stdin.readline()
print("\nThe Longest word in the sentence is {}".format(longestWord(sen)))
sys.stdin.readline()
我已经使用调用sys.stdin.readline(),因为输入()会给我一个EOF错误。这解决了EOF错误,但现在我得到另一个错误指向打印结束参数说它的语法错误。只有当我将它作为顶层脚本运行时才会出现此问题,但在IDLE中正常运行。如果我使用input()而不是sys.stdin.readline(),那么将它作为顶级脚本运行时,会为我在打印状态的'end'参数处提供一个SyntaxError。
我再改剧本2.x版
if __name__ == '__main__':
sen = raw_input("Enter a sentence: ")
print "\nThe Longest word in the sentence is {}".format(longestWord(sen))
raw_input()
该脚本正常工作在Python 2.7,而且在3.4的工作。我期待的raw_input函数和打印语句的错误,但我没有得到它们。 但是这两个脚本都在IDLE 3.4中正常工作。 有人可以解释发生了什么?
脚本失败的地方?这在你的文本中不太清楚。 –