return 문을 포함하지만 값을 반환하지 않는 함수가 정의되어 있습니다. 다음과 같이 내 코드는 다음과 같습니다함수 반환 값 없음
def seed(addy):
# urllib2 stuff is here
seed_result = re.search('<td>Results 1 - \d+ of (\d+)',seed_query) # searches for '<td>Results 1 - x of y', captures 'y'
seed_result = seed_result.group(1) # this is 'y' from above
# there's a call to a different function here which works properly
# other stuff going on here pertaining to addy but seed_result still has my string
# now I want to return the seed_result string...
return seed_result
# ... some code outside of the seed function, then I call seed...
seed(addy)
print "Result is %s" % seed_result
내가 그것을 "초기화"를 함께하고 함수의 외부 seed_result를 정의하지 않고이 작업을 시도했지만이는 결과에 영향이 미치지 최종 수익률 "에서 내 인쇄 문 결과는 "- seed_result가 없습니다. 나는 그것이 올바른지 어떻게 믿을지라도 return 문에서 괄호 안에 seed_result를 감쌌다. 팸은 차이를 만들지 않았습니다.
A는 Python 셸에서 매우 기본적인 기능이지만 유사한 기능을 설정하고 여기에서 설명한대로 호출했지만 작동합니다. 내가 무엇을 놓치고 있는지 모르겠다.
의견 및 안내에 감사드립니다.
결과가 "없음"인 함수를 호출하기 위해 print 문을 수행하려고했습니다. * scratching head * –
파이썬 쉘에서 작동하는 이유는 쉘이 평가 된 표현식의 결과를 출력한다는 것입니다. Jon Skeet이 말했듯이, 프로그램에서 그것을 잡으려면 변수에 할당해야합니다. –