Cannot find python xlrd version

I used xlrd inside python. However, xlrd does not seem to provide a standard way to find the version number! I tried:

  • xlrd.version()
  • xlrd.__version__
  • xlrd.version
  • xlrd.version
  • xlrd.version()
+4
source share
1 answer

You almost got it: xlrd.__VERSION__ .

It is usually useful to see the available attributes and methods by calling dir : dir(xlrd) .


You can even iterate over dir() results if inside version :

 >>> import xlrd >>> getattr(xlrd, next(item for item in dir(xlrd) if 'version' in item.lower())) '0.9.3' 

A more reliable way that will work for any installed package is to use pkg_resources :

 >>> import pkg_resources >>> pkg_resources.get_distribution("xlrd").version '0.9.3' 
+11
source

Source: https://habr.com/ru/post/1483810/


All Articles