This article describes the Python access to Linux file version information, company name and product name method, share for everyone to reference. Specifically as follows:
The difference is described in the previous article. This example obtains the file version information under Linux, mainly through the Pefile module parsing the string in the file. The code is as follows:
def _get_company_and_product (self, File_path): "" "Read all properties of the
given file return them as a Dictiona Ry.
@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 "Produ" Ctname ":
productName = v
if not companyName:
companyName = None
if not productName:
ProductName = None return
(CompanyName, ProductName)
Here we only need the company name information and product name information. Information such as the version number is also in the string resource.
I hope this article will help you with your Python programming.