这是一个noob问题,我相当肯定该函数将只执行一次,但我想清楚。我正在使用python和urllib登录到一个网站。登录后,会有一个与我的帐户相关联的用户标识,这将允许我导航该网站。然而,我不希望每次调用该变量都要登录,所以我想知道如果调用该变量会导致再次登录,或者如果登录函数只在我明确运行登录函数时才执行?设置一个函数=变量,将导致函数执行每次变量被调用?
def login(username,pw):
#some calls to HTTP server using urllib
return user_id
user_id = login('[email protected]','mypassword')
def search():
#calls to HTTP to perform a search on a page on the website
#I need to reference user_id and I want to know if user_id will simply be
# the integer user_id or if it will call the login function each time I reference it
谢谢。我知道这是一个我应该知道的简单问题,但我想确定。再次感谢! – 2013-03-11 16:48:59