【问题标题】:Is there a way to show the amount of time spent developing a Jupyter notebook?有没有办法显示开发 Jupyter 笔记本所花费的时间?
【发布时间】:2019-03-31 00:32:56
【问题描述】:

有没有办法检查我开发 Jupyter Notebook 所花费的时间?

我猜想从创建 .ipynb(因为它不断保存)到最后一次保存的时间?

有些应用程序会显示文件已被编辑的时间量,因此类似。

【问题讨论】:

    标签: python jupyter-notebook


    【解决方案1】:

    感谢@cardamom 为我指明了正确的方向。我将此添加到一个单元格中以将笔记本的名称放入 nb_name

    %%javascript
    IPython.notebook.kernel.execute('nb_name = "' + IPython.notebook.notebook_name + '"')
    

    然后把它放到另一个单元格中,它似乎给了我答案……只需要一点格式。

    # Get the path from
    path = !echo %cd%
    
    # Combine the path and filename
    completepath = path[0] + '\\' + nb_name
    
    filecreationtime = os.path.getatime(completepath)
    filecreationtime = datetime.utcfromtimestamp(filecreationtime)
    
    now = datetime.now()
    print(f'Notebook: {nb_name}')
    print(f'At path: {path[0]}')
    print(f'Dev Time: {str(now - filecreationtime)}')
    

    问题是,增加一小时后,它似乎并不完全正确。我使用的是windows,所以我想它必须归结为os.path.getctime。

    【讨论】:

    • 可能是这个 - stackoverflow.com/a/25887393/4288043 他们将 datetime.datetime.now() 称为“幼稚”时间,我认为如果你关心那个时间,你必须做更多的事情。
    【解决方案2】:

    如果您将以下内容放入单元格中,它可能会在 Windows 系统上执行此操作:

    import sys
    import os
    from datetime import datetime
    completepath = sys.argv[0]
    filecreationtime = os.path.getmtime(completepath)
    filecreationtime = datetime.utcfromtimestamp(filecreationtime)
    now = datetime.now()
    str(now - filecreationtime)
    

    我使用的是 Linux 系统,似乎无法真正访问创建日期,如 here 所述

    也许有一个变量可以在创建时以某种方式写入 .ipynb 文件以解决此问题。

    【讨论】:

    • 感谢@cardamom,这很有帮助。
    猜你喜欢
    • 2021-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-27
    • 2018-10-13
    • 1970-01-01
    • 2020-03-23
    • 2021-07-12
    相关资源
    最近更新 更多