[问题] variable的定义

楼主: popjuice (pop juice)   2013-12-28 15:47:04
小弟想问个很基本的问题
当执行这段code的时候(找网页连结的)
def get_next_target(page):
start_link = page.find('<a href=')
start_quote = page.find('"', start_link)
end_quote = page.find('"', start_quote + 1)
url = page[start_quote + 1:end_quote]
return url, end_quote
get_next_target('The site is called Google <a href= "www.google.com">')
print url
为什么系统会说 name 'url' is not defined
谢谢!
作者: darkgerm (黑骏)   2013-02-28 15:49:00
因为 url 是 get_next_target 的 local variable
作者: ccwang002 (亮)   2013-02-28 15:58:00
应该要 ul, edquote = get_next_target(...); print ul
楼主: popjuice (pop juice)   2013-02-28 16:35:00
谢谢!

Links booklink

Contact Us: admin [ a t ] ucptt.com