如何获取运行ipynb文件的路径?

2024-03-29 00:14:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个程序可以读取多个子文件夹的文件。在

我以前写的代码有:

^{1}$

然后我打开几个文件说

^{pr2}$

如何更改代码以便其他人可以使用它?我使用的是Jupyter笔记本,所以文件和sys(argv[0])似乎不工作。在

我看过这些:

  1. How to get an absolute file path in Python
  2. How do I get the parent directory in Python?

Tags: 文件to代码in程序文件夹anget
1条回答
网友
1楼 · 发布于 2024-03-29 00:14:40

使用获取当前工作目录

def join_current_dir(file):
    """Join filepath with current file directory"""
    cwd = os.getcwd()
    return os.path.join(cwd, file)

相关问题 更多 >