python获取Linux下文件版本信息、公司名和产品名的方法

yipeiwu_com6年前Python基础

本文实例讲述了python获取Linux下文件版本信息、公司名和产品名的方法,分享给大家供大家参考。具体如下:

区别于前文所述。本例是在linux下得到文件版本信息,主要是通过pefile模块解析文件 中的字符串得到的。代码如下:

  def _get_company_and_product(self, file_path): 
    """ 
    Read all properties of the given file return them as a dictionary. 
    @return: a tumple, (company, product) 
    """ 
    mype = pefile.PE(file_path) 
    companyName = "" 
    productName = "" 
      
    if hasattr(mype, 'VS_VERSIONINFO'): 
      if hasattr(mype, 'FileInfo'): 
        for entry in mype.FileInfo: 
          if hasattr(entry, 'StringTable'): 
            for st in entry.StringTable: 
              for k, v in st.entries.items(): 
                if k == u"CompanyName": 
                  companyName = v 
                elif k == u"ProductName": 
                  productName = v 
    if not companyName: 
      companyName = None 
    if not productName: 
      productName = None 
    return (companyName, productName) 

这里我们只要了公司名称信息和产品名称信息。至于版本号之类的信息也是在字符串资源中。

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Django中几种重定向方法

这里使用的是django1.5 需求: 有一个界面A,其中有一个form B, 前台提交B之后,后台保存数据之后,返回界面A,如果保存失败需要在A界面提示错误。 这里就需要后台的重定向,...

Python 内置函数complex详解

英文文档: class complex([real[, imag]]) Return a complex number with the value real + imag*1j or...

2款Python内存检测工具介绍和使用方法

去年自己写过一个程序时,不太确定自己的内存使用量,就想找写工具来打印程序或函数的内存使用量。这里将上次找到的2个内存检测工具的基本用法记录一下,今后分析Python程序内存使用量时也是需...

详解Python Opencv和PIL读取图像文件的差别

前言 之前在进行深度学习训练的时候,偶然发现使用PIL读取图片训练的效果要比使用python-opencv读取出来训练的效果稍好一些,也就是训练更容易收敛。可能的原因是两者读取出来的数...

django实现用户注册实例讲解

创建一个apps包 专门来放子应用 创建users子应用 处理用户事务 追加导包路径 在settings中用 print(sys.path) 查看现有导包路径 sys.path.i...