我尝试使用 Python 访问 Excel 文件,但收到以下错误:
FileNotFoundError: [Errno 2] No such file or directory: 'input/sales-feb-2014.xlsx'
你能帮我定义文件的路径吗?
Python 代码:
from xlrd import open_workbook
sheet = open_workbook('input/sales-feb-2014.xlsx').sheet_by_index(0)
print (sheet.cell_value(3,0))
最佳答案
您需要添加 open_workbook(your_full_path_comes_here)
的完整路径或更改您之前使用的目录。
您可以在调用变量之前使用 os
模块。
import os
os.chdir(r'...your/path/input')
关于python - excel文件的相对路径,python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51898409/