[問題] 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