LeoHsiao1 / pyexiv2

Read and write image metadata, including EXIF, IPTC, XMP, ICC Profile.
GNU General Public License v3.0
201 stars 39 forks source link

[suggestion] Add support for pathlib.Path #36

Closed rysson closed 3 years ago

rysson commented 3 years ago

Path for pathlib is recommended and very nice way to handle system paths. Could you add support it in pyexiv2.Image?

LeoHsiao1 commented 3 years ago

Hello! After receiving your suggestion, I have read the official pathlib documentation these two days, My conclusion is that pathlib has fewer features than os.path. So I'm not going to use pathlib for long.

Also, the result of calling pathlib does not conform to my habit of using os.path. For example:

D:\>python
Python 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import Path
>>> Path('../test/1.txt').resolve() 
WindowsPath('D:/test/1.txt')
>>> Path('./test/1.txt').resolve()       # Failed to convert to absolute path
WindowsPath('test/1.txt')
>>>
>>> import os
>>> os.path.abspath('./test/1.txt')
'D:\\test\\1.txt'

Finally, I recommend that you convert your pathlib.Path to a normal string and then use:

p = pathlib.Path('1.jpg')
pyexiv2.Image(str(p))
rysson commented 3 years ago

Sure, I've used it in this way already. os.path works with pathlib too (as well as with str), so there should be no regression.

BTW. I started using pathlib just a few month ago (after years of ignoring it). I understand and close the issue. Use str(path) is not so difficult :-)

github-actions[bot] commented 3 years ago

This issue has been automatically closed because there has been no activity for a month.