我到处寻找答案,似乎这是一个简单的问题。唉,没有骰子。在
问题:我无法从终端“运行”python文件(macosx10.9.2)
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>;>>
浏览到创建了“pthw_e01.py”的文件后:
$python pthw_e01.py
$
总之,当我尝试运行python脚本时,什么都不会发生(我相信这是一个脚本,不是一个文件吗?)。在
如果有助于您回答,我在终端中尝试运行的python只是一堆print语句(见下文):
print "Hello World!" print "Hello Again" print "I like typing this." print "This is fun." print 'Yay! Printing.' print "I'd much rather you 'not'." print 'I "said" do not touch this.'
您可能是在打开文件时保存的,文件是空的,然后在键入文本后不再保存文件。检查你的文件大小,看看它是否为零。再次保存并重新运行。每次进行更改和运行时都必须保存它
如果它们在一个大脚本中,则需要将它们放在单独的行中,或者在shell中分别输入每一行。Python通常使用新行来确定每个语句的结束位置。在
pthw_e01.py:
从上面的屏幕截图来看,您试图在解释器中运行python文件,而不是在终端中实际运行程序。如果您愿意,您可以在解释器中运行每个打印行,但不能运行整个文件。不只是键入python并打开解释器,而是键入python pthw_e01.py,它应该会将您的程序显示到终端。在
相关问题 更多 >
编程相关推荐