【发布时间】:2020-01-26 14:07:10
【问题描述】:
我正在尝试使用 openpyxl 模块加载 .xlsx 文件。下面的文件路径适用于 xlrd 模块,但我已经尝试过这个和其他多个版本,包括仅带有 openpyxl 的“pytestsheet.xlsx”。每次我得到一个 FILENOTFOUNDERROR。这是在 Mac 上。
import openpyxl
path = "~/Documents/pytestsheet.xlsx"
wb = openpyxl.load_workbook(path)
【问题讨论】:
-
~不会像在 shell 中那样自动扩展...您需要明确地这样做,例如:os.path.expanduser("~/Documents/pytestsheet.xlsx")
标签: python excel macos path openpyxl