Creating A Pythonic API Binding
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Jun 8 05:04:24 EDT 2016
On Wednesday 08 June 2016 12:31, Lawrence D’Oliveiro wrote:
> The wrong way:
[...]
> The right way <https://github.com/ldo/mtpy>:
That's quite good.
A few minor issues:
I don't understand why you have a method that returns files called
"get_children".
And I would expect that if you passed a relative file name to create_folder()
it should create a folder relative to (1) the current working directory, if the
Device has such a concept; (2) your home or user directory, if the Device has
such a concept; or (3) relative to the photos directory. Not relative to the
root of the Device, that is very surprising.
Also, it would be good if you could make dev a context manager, so that you
don't have to manually close them:
with mtpy.get_raw_devices()[0].open() as dev:
p = dev.get_descendant_by_path("/DCIM/Camera")
p.get_children()
# dev is automatically closed
But other than that, it looks quite nice. Thank you for posting the link.
--
Steve
More information about the Python-list
mailing list