Jupyter Notebook:文件“ .ipynb_checkpoints”不存在-Python

时间:2018-09-28 08:47:32

标签: python pandas jupyter-notebook jupyter

我的代码如下:

os.chdir('/media/data2/jupyter_notebooks/sacherr/Daten')

i=1
for f in os.listdir():
    mdf = MDF(f)
    df = mdf.export('pandas')
print(i)
i=i+1

我总是得到这个错误代码:

MdfException: File ".ipynb_checkpoints" does not exist

我该如何解决?

谢谢你, R

1 个答案:

答案 0 :(得分:0)

您的问题如下:MDF构造函数需要文件的完整路径。但是os.listdir()仅提供文件名。尝试将目录路径添加到f变量中。

我从MDF source code那里得到了这个主意:

    def __init__(self, name=None, memory='full', version='4.10', **kwargs):
    if name:
        memory = validate_memory_argument(memory)
        if is_file_like(name):
            file_stream = name
        else:
            if os.path.isfile(name):
                file_stream = open(name, 'rb')
            else:
                raise MdfException('File "{}" does not exist'.format(name))
        file_stream.seek(0)

那样:

i=1
for f in os.listdir('/media/data2/jupyter_notebooks/sacherr/Daten/'):
    f = '/media/data2/jupyter_notebooks/sacherr/Daten/'+f
    mdf = MDF(f)
    df = mdf.export('pandas')
print(i)
i=i+1