我是python中的新手。试着靠自己学习。 下面是我的python程序。当我试图在Powershell中运行它时。它只是卡住了。 它永远不会显示任何输出。我在屏幕上看不到任何错误。
from sys import argv
script, name = argv
print "this is: ", script
print "my name is: ", name
age = raw_input("what is your age: ")
height = raw_input("what is your height")
print "so your name is %s, your age is %s and height is %r" %(name, age, height)
由于
答案 0 :(得分:0)
我不知道为什么你没有在PowerShell中出现任何错误,但代码存在很多问题,其中大多数问题,很可能是由于错误的复制粘贴,但导致挂起的问题你的谎言:
script, name = argv
为了解释它,请参考to the documentation:
sys.argv传递给Python脚本的命令行参数列表。 argv [0]是脚本名称(它是依赖于操作系统的 这是一个完整的路径名或不是)。如果使用命令执行命令 -c命令行选项到解释器,argv [0]设置为字符串'-c'。如果没有脚本名称传递给Python解释器, argv [0]是空字符串。
所以你要找的是这样的(用固定的线条):
from sys import argv
script, name = argv[0], argv[1]
print "this is: ", script
print "my name is: ", name
age = raw_input("what is your age: ")
height = raw_input("what is your height")
print "so your name is %s, your age is %s and height is %r" %(name, age, height)
答案 1 :(得分:0)
此代码可以使用:
from sys import argv
script, name = argv
print ("this is: ", script)
print ("my name is: ", name)
age = input("what is your age: ")
height = input("what is your height")
print ("so your name is {}, your age is {} and height is {}" .format(name, age, height))
Python 3中有几个更新,所以我猜这就是为什么必须有一些语法错误。
我也是初学者(这是我在stackoverflow的第一个答案),我一直在努力学习“学习Python”这本书。我遇到了和你一样的问题: