功能返回但没有价值

Bit*_*ket -1 python return function

我有一个定义的函数,它包含一个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
Run Code Online (Sandbox Code Playgroud)

我已经尝试了这个,有或没有在函数之外定义seed_result来"初始化"它,但这对结果没有影响,这就是我最后的print语句产生"Result is" - 没有seed_result.我还在return语句中将seed_result包装在括号中,但我相信我的方法是正确的.parens并没有什么不同.

在Python shell中设置一个非常基本但相似的函数,并像我在这里一样调用它,但是它可以工作.不知道我错过了什么.

感谢您的反馈和指导.

Jon*_*eet 9

您没有使用返回值(例如,将其分配给变量).试试这个:

result = seed(addy)
print "Result is %s" % result
Run Code Online (Sandbox Code Playgroud)