正在从桌面(我的电脑)读取文件.xlsx,该文件已存在,扩展名相同#基于JupyterLab的交互式开发环境

2024-09-30 00:40:58 发布

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

代码:

import xlrd
    loc = input(r'Enter the path of your file: ')
    print(loc)
    #loc="C:\Users\anuj.masand\Desktop\PrototypeIncidentAudit.xlsx"
    assert os.path.exists(loc), "I did not find the file at, "+str(loc)

    wb = xlrd.open_workbook(loc)
    Print("I got it")

错误:

AssertionError                            Traceback (most recent call last)
<ipython-input-16-4ab769c51fe8> in <module>
      3 print(loc)
      4 #loc="C:\Users\anuj.masand\Desktop\PrototypeIncidentAudit.xlsx"
----> 5 assert os.path.exists(loc), "I did not find the file at, "+str(loc)
      6 
      7 wb = xlrd.open_workbook(loc)

AssertionError: I did not find the file at, C:\Users\anuj.masand\Desktop\PrototypeIncidentAudit.xlsx

Why am I getting this error if it's already there on my desktop?


Tags: thepathnotfindxlsxuserslocat
2条回答

由于我正在开发一个在线的基于web的交互式开发环境,我所需要做的就是将文档上传到仪表板(/home/jovyan/binder/),只需转到菜单栏File>;打开

I have uploaded my document there and now its working fine with path change ofcourse(/home/jovyan/binder/PrototypeIncidentAudit.xlsx')

试试这个:

import xlrd
import os

loc = input(r'Enter the path of your file: ')
print(loc)

if os.path.isfile(loc):
    wb = xlrd.open_workbook(loc)
    print("I got it")
else:
    print(f"I did not find the file at {loc}.")

相关问题 更多 >

    热门问题