python脚本不能在PowerShell中工作
问题描述:
我是一个Python新手。试图通过我自己学习。 以下是我的python程序。当我试图在Powershell中运行它时。它只是卡住了。 它永远不会显示任何输出。我在屏幕上看不到任何错误。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)
感谢
答
我不知道为什么你没有得到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)