当前位置: 移动技术网 > IT编程>脚本编程>Python > python获取Linux下文件版本信息、公司名和产品名的方法

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

2019年03月25日  | 移动技术网IT编程  | 我要评论

油饼母鸡汤,江珊张博,二甲苯麝香

本文实例讲述了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程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网