小编mev*_*303的帖子

我应该重新使用游标对象还是使用 mysql.connector 创建一个新游标对象?

我应该重用游标对象还是为每个查询创建一个新游标对象?

重新使用光标:

    # we're going to connect to s3 and mysql
    db = mysql_connect(host="localhost",
                       user="user",
                       passwd="pass",
                       database="db")

    # Reusing the cursor
    cursor = db.cursor()

    # loop through all the files in the bucket one by one
    for key in bucket.get_all_keys():

        # the document id is the filename in the s3 bucket
        doc_id = key.name.split("/")[-1]
        cursor.execute("SELECT document_name FROM laws_docs WHERE id = %i", (doc_id,))
        doc_name = cursor.fetchone()[0]

    cursor.close()
Run Code Online (Sandbox Code Playgroud)

- 或者 -

每次新光标:

    # we're going to connect to s3 and mysql …
Run Code Online (Sandbox Code Playgroud)

mysql-connector mysql-python python-3.x

9
推荐指数
1
解决办法
4035
查看次数

使用 apt-get WITHOUT Docker 在 Azure Functions 中安装依赖项

我正在尝试将 Azure Functions 与 Python 结合使用并制定消费计划,以使用 Selenium 和 Firefox 抓取网页。对于它的使用方式,使用消费计划更实用(也更便宜),这意味着我不能使用 Docker 容器。

到目前为止,我已经能够成功地包含和路径 Firefox 的geckodriver二进制文件以及二进制文件。我收到以下错误:

1571952497758   mozrunner::runner   INFO    Running command: "/home/site/wwwroot/SharedCode/bin/firefox/firefox" "-marionette" "--headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileFyNhwV"
XPCOMGlueLoad error for file /home/site/wwwroot/SharedCode/bin/firefox/libmozgtk.so:
libgtk-3.so.0: cannot open shared object file: No such file or directory
Couldn't load XPCOM.
Run Code Online (Sandbox Code Playgroud)

我的印象是,如果 Firefox/Selenium 在无头模式下运行(它是),则不需要 GTK:

1571952497758   mozrunner::runner   INFO    Running command: "/home/site/wwwroot/SharedCode/bin/firefox/firefox" "-marionette" "--headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileFyNhwV"
XPCOMGlueLoad error for file /home/site/wwwroot/SharedCode/bin/firefox/libmozgtk.so:
libgtk-3.so.0: cannot open shared object file: No such file or directory …
Run Code Online (Sandbox Code Playgroud)

python firefox selenium azure-functions

5
推荐指数
1
解决办法
512
查看次数

单独open()是否保持文件句柄打开?

在执行完成后,单个调用open()而不将其分配给变量会关闭文件句柄吗?

import json
_keyfile = json.load(open("s3_key.json", "r"))
Run Code Online (Sandbox Code Playgroud)

如果你打电话给.read()呢?

import json
_keyfile = json.loads(open("s3_key.json", "r").read())
Run Code Online (Sandbox Code Playgroud)

python python-3.x

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