找不到python xlrd版本

Pau*_*ery 4 python excel packages version xlrd

我一直xlrd在python中使用.但是,xlrd似乎没有提供找到其版本号的标准方法!我试过了:

  • xlrd.version()
  • xlrd.__version__
  • xlrd.version
  • xlrd.VERSION
  • xlrd.VERSION()

ale*_*cxe 13

你几乎得到了它:xlrd.__VERSION__.

通常通过调用dir来查看可用的属性和方法是有用的:dir(xlrd).


你甚至可以遍历结果,dir()看看是否version在里面:

>>> import xlrd
>>> getattr(xlrd, next(item for item in dir(xlrd) if 'version' in item.lower()))
'0.9.3'
Run Code Online (Sandbox Code Playgroud)

一种更可靠的方法,适用于任何已安装的包,是使用pkg_resources:

>>> import pkg_resources
>>> pkg_resources.get_distribution("xlrd").version
'0.9.3'
Run Code Online (Sandbox Code Playgroud)