小编sel*_*bok的帖子

在Python中为一次性对象分配名称是否更好?

这不是"为什么我的代码不运行"的问题.它是"我的代码如何/为什么工作"的问题.我希望从这个具体案例中概括一下,了解将来适用于类似情况的广泛规则.

我为此做了一些搜索(谷歌和StackOverflow),但没有看到任何直接回答这个问题的东西.当然,我不完全确定如何最好地提出这个问题,并且可能使用了错误的术语.我欢迎对标题和标签的建议编辑.

我有以下功能(使用请求模块):

def make_session(username,password,login_url):
#The purpose of this function is to create a requests.Session object,
#update the state of the object to have all of the cookies and other
#session data necessary to act as a logged in user at a website, and
#return the session to the calling function.

    new_session = requests.Session()

    login_page = new_session.get(login_url)

    #The function get_login_submit_page takes the previously
    #created login_page, extracts the target of the login form
    #submit, and returns it as a …
Run Code Online (Sandbox Code Playgroud)

python python-2.7

0
推荐指数
1
解决办法
98
查看次数

标签 统计

python ×1

python-2.7 ×1