Python gets the method of file version information, company name and product name under Linux _python

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.