首页 > 解决方案 > Python - gphoto2 如何弄清楚函数的作用?

问题描述

我正在玩 gphoto2,发现该camera对象具有公共功能file_get_info()。我想知道:

  1. 这个函数是做什么的
  2. 怎么称呼它

但到目前为止,我还没有找到任何有关它的信息。


这就是我所做的:

import gphoto2 as gp

portInfoList = gp.PortInfoList()
portInfoList.load()
abilitiesList = gp.CameraAbilitiesList()
abilitiesList.load()
cams = abilitiesList.detect(portInfoList)

for name, addr in cams:
    print("%s at port %s"%(name, addr))
    idx = portInfoList.lookup_path(addr)
    camera = gp.Camera()
    camera.set_port_info(portInfoList[idx])
    camera.init()
camera.file_get_info()

这就是我得到的:

TypeError: Camera_file_get_info expected at least 2 arguments, got 0

更令人沮丧的是,无论我多么努力地谷歌,我都找不到有关该Camera_file_get_info功能的任何信息。

我接近这个错误吗?

标签: python-3.xlibgphoto2

解决方案


对象上的file_get_info方法Camera是 libgphoto2 函数的 Pythonic 版本gp_camera_file_get_info。这将是一个更好的网络搜索术语。

有几种方法可以获取您正在寻找的信息。像其他 Python 模块一样,您可以使用 pydoc:

pydoc3 gphoto2.Camera.file_get_info

Help on method_descriptor in gphoto2.Camera:

gphoto2.Camera.file_get_info = file_get_info(...)
    file_get_info(char const * folder, char const * file, Context context)

    Retrieves information about a file.  

    Parameters
    ----------
    * `camera` :  
        a Camera  
    * `folder` :  
        a folder  
    * `file` :  
        the name of the file  
    * `info` :  
    * `context` :  
        a GPContext  

    Returns
    -------
    a gphoto2 error code

    See also gphoto2.gp_camera_file_get_info

这取自“C”文档,因此参数列表有点混乱 -info在 C 版本中是一个参数,但在 Python 中不是。您需要的两个参数是folderfile- 这些参数告诉函数您想要有关哪个文件的信息。

您可能更喜欢直接使用 C 文档:http ://www.gphoto.org/doc/api/gphoto2-camera_8h.html#adda54321b1947b711d345936041f80c7这包括info结构的链接。

最后,list-files.py包含的示例程序python-gphoto2显示了file_get_info.


推荐阅读