2014-12-10 6 views
0

PyScripter에서 다음 코드를 올바르게 작동시키는 방법을 잘 모릅니다.PyScripter Import ARGV

from sys import argv 

script, user_name = argv 
prompt = '> ' 

print "Hi %s, I'm the %s script." % (user_name, script) 
print "I'd like to ask you a few question." 
print "Do you like me %s?" % user_name 
likes = raw_input(prompt) 

print "Where do you live %s?" %user_name 
lives = raw_input(prompt) 

print "What kind of computer do you have?" 
computer = raw_input(prompt) 

print """ 
Alright, so you said %r about liking me. 
You live in %r. Not sure where the fuck that is! 
And you have a %r computer. It's obviously a piece of shit! 
""" % (likes, lives, computer) 

감사합니다.

+0

을 그래서 무슨 문제가 정확히? – Kasramvd

+0

ValueError : 압축을 풀고 스크립트를 강조 표시하기 위해 1 개 이상의 값이 필요합니다. user_name = argv –

답변

0

argv의 변수를 2로 풀면 터미널에 user_name을 전달해야합니다.

from sys import argv 
script, user_name = argv 

print user_name 

데모 :

/Desktop$ python p.py userrrr 
userrrr 

하지만 당신은 런타임에 사용자 이름을 전달 해달라고하면 당신이 오류를 얻을 것이다 :

~/Desktop$ python p.py 
Traceback (most recent call last): 
    File "p.py", line 51, in <module> 
    script, user_name = argv 
ValueError: need more than 1 value to unpack 
+0

나는 내가 새 것이고 간단한 설명을 추가해야한다고 생각합니다! –

+0

@JustinKowalsky 예 런타임에 추가해야합니다! – Kasramvd