Accept pathlib objects in addition to strings #146
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. 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!