手机
当前位置:查字典教程网 >脚本专栏 >python >python获取Linux下文件版本信息、公司名和产品名的方法
python获取Linux下文件版本信息、公司名和产品名的方法
摘要:本文实例讲述了python获取Linux下文件版本信息、公司名和产品名的方法,分享给大家供大家参考。具体如下:区别于前文所述。本例是在lin...

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

【python获取Linux下文件版本信息、公司名和产品名的方法】相关文章:

Python中文件遍历的两种方法

python逐行读取文件内容的三种方法

python实现监控linux性能及进程消耗性能的方法

使用Python获取Linux系统的各种信息

python3访问sina首页中文的处理方法

Python列表推导式的使用方法

python中文乱码的解决方法

python 获取本机ip地址的两个方法

Python中使用动态变量名的方法

Python获取脚本所在目录的正确方法

精品推荐
分类导航