本文實例講述了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程序設計有所幫助。
新聞熱點
疑難解答