Python Windows中的文件路径
我试图读取excel工作簿时遇到windows路径错误。我试过os和pathlib。代码显示了不同的变化Python Windows中的文件路径,python,windows,Python,Windows,我试图读取excel工作簿时遇到windows路径错误。我试过os和pathlib。代码显示了不同的变化 def main(): infilename = ('c:\Testing\Python\EET_Report.xlxs') tried infilename = pathlib.Path('c:/Testing/Python/EET_Report.xlxs') tried infilename = pathlib.PureWindowsPath('c:/Testi
def main():
infilename = ('c:\Testing\Python\EET_Report.xlxs')
tried infilename = pathlib.Path('c:/Testing/Python/EET_Report.xlxs')
tried infilename = pathlib.PureWindowsPath('c:/Testing/Python/EET_Report.xlxs')
# open file
inwb = xlrd.open_workbook(infilename)
运行程序时出现的错误:
没有这样的文件或目录:'c:\\Testing\\Python\\EET\u Report.xlxs'
该文件名上的扩展名可能应该是“xlsx”,而不是“xlxs”。该文件名上的扩展名可能应该是“xlsx”,而不是“xlxs”。您可能需要使用反斜杠取消某些字符的显示
def main():
infilename = ('c:\/Testing\/Python\/EET_Report.xlxs')
tried infilename = pathlib.Path('c:\/Testing\/Python\/EET_Report.xlxs')
tried infilename = pathlib.PureWindowsPath('c:\/Testing\/Python\/EET_Report.xlxs')
# open file
inwb = xlrd.open_workbook(infilename)
您可能需要使用反斜杠取消某些字符的显示
def main():
infilename = ('c:\/Testing\/Python\/EET_Report.xlxs')
tried infilename = pathlib.Path('c:\/Testing\/Python\/EET_Report.xlxs')
tried infilename = pathlib.PureWindowsPath('c:\/Testing\/Python\/EET_Report.xlxs')
# open file
inwb = xlrd.open_workbook(infilename)
请尝试
infilename=(r'c:\Testing\Python\EET_Report.xlxs')
正如@jjramsey所说,您可能在文件扩展名上有错误。工作簿文件应具有.xlsx
扩展名tryinfilename=(r'c:\Testing\Python\EET_Report.xlxs')
正如@jramsey所说,您可能在文件扩展名上有错误。工作簿文件应具有.xlsx
扩展名,而此代码段可能是解决方案,包括解释确实有助于提高文章质量。请记住,您将在将来回答读者的问题,而这些人可能不知道您的代码建议的原因。虽然此代码片段可能是解决方案,但包含解释确实有助于提高您的文章质量。请记住,您将在将来回答读者的问题,这些人可能不知道您的代码建议的原因。