Accept pathlib objects in addition to strings
#146
Closed
opened 2 years ago by Ghost
·
1 comments
Loading…
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Since version 3.4 (2014), Python has shipped with
pathlib
which provides objects to make handling paths easy and consistent across platforms. Currently, if you pass aPath
object toimg2pdf
, you receive this error:You have to loop through the
Path
objects and convert them withstr()
before passing them toimg2pdf
. It would be great if users could passPath
objects directly.You don't hve to convert them with
str()
. You can either:pathlib.Path.open()
and pass the resulting object toimg2pdf
(but don't forget to close the resulting object)pathlib.Path.read_bytes()
and pass the resulting byte string toimg2pdf
-- img2pdf will slurp the file contents into memory anywaysBut I agree that it should be possible to just pass a
pathlib.Path
object without having to jump through any extra hoops.In
272fe0433f
I added that img2pdf will also accept objects that have a member function calledread_bytes
which coverspathlib.Path
objects but also anything else implementing that function.Thanks!