Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pathlib.Path file paths #1124

Closed
zoquda opened this issue Jun 23, 2019 · 0 comments · Fixed by #1126
Closed

Add support for pathlib.Path file paths #1124

zoquda opened this issue Jun 23, 2019 · 0 comments · Fixed by #1126

Comments

@zoquda
Copy link
Contributor

zoquda commented Jun 23, 2019

Description

Currently the xlwings API does not seem to support file paths that are formatted as pathlib.Path object. The following code example demonstrates this:

# OS: Windows 10
# xlwings: 0.15.8
# excel: 2013
# python: 3.7.3

from pathlib import Path
import xlwings as xw

# Create dummy excel file
book = xw.Book()
book.save('example_file.xlsx')
book.close()

# Attempt to connect to excel file using Pathlib path
file_path = Path('example_file.xlsx').resolve()
xw.Book(file_path)

The subsequent error traceback is:

AttributeError                            Traceback (most recent call last)
~\Desktop\example.py in <module>
      9 # Attempt to connect to excel file using Pathlib path
     10 file_path = Path('example_file.xlsx').resolve()
---> 11 xw.Book(file_path)

C:\Software\Anaconda3\lib\site-packages\xlwings\main.py in __init__(self, fullname, impl)
    474         if not impl:
    475             if fullname:
--> 476                 fullname = fullname.lower()
    477
    478                 candidates = []

AttributeError: 'WindowsPath' object has no attribute 'lower'

The addition of support for pathlib.Path file paths is hereby proposed as enhancement of xlwings.

Rationale

Use of pathlib.Path objects for file paths is attractive to users because (compared to string object file paths) they are usually easier to work with and more consistent across operating systems (see Python 3's pathlib Module: Taming the File System for more details). The pathlib module is readily available, since it is part of python's standard library since version 3.4.

zoquda added a commit to zoquda/xlwings that referenced this issue Jun 25, 2019
Previously all path input arguments had to be a string object. Path
input arguments now accept any object that is an instance of
`os.PathLike` as well.

Closes: xlwings#1124
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants