Python gadget ___ reads a specific string in a specified file into an Excel table __python

Source: Internet
Author: User
Tags parent directory
#coding: UTF8 import os import os.path import XLWT import XLRD #---Get the current path---filepath=os.getcwd () #---Specify the test path---fil   E01= ' F:\SVNBaloon\BalloonBlast\Assets\Scripts ' #---Start a specific identity---' Debug.Log ("' #---End a specific identification---endsign= '); ' ---Create a table---getwordexcel=xlwt.   Workbook () #---Create Sheet---gettable=getwordexcel.add_sheet (' getword ', cell_overwrite_ok=true) #---Number of rows---index = 0 # ---traverse parent in the corresponding path: dirnames All folders filenames all file names---for parent,dirnames,filenames in Os.walk (FilePath): #- --Traverse All files---for filename in filenames: #---set/get the current file parent directory---totalfilepath=os.path.join (parent,fi
            LENAME) #---Get files with the suffix. cs or. txt---if filename.endswith ('. cs ') or Filename.endswith ('. Lua '):
            #---Get file full path---totalfile=os.path.abspath (totalfilepath) #---Open read file ' R ' for read ' W ' for write Fileinfo02=open (Totalfilepath, ' R ') #---Traverse the current file to view each row---for FILE02 in fileInfo#---Remove each line of line feed ' \ n '---file02 = file02.strip (' \ n ') #---judgment begins to mark and end Identifies whether it exists in the current row---if startsign in File02 and Endsign in FILE02: #---for cutting operations (that is, the string
                        Cutting)---startIndex = file02.index (startsign) if StartIndex >= 0: StartIndex + = Len (startsign) endindex = File02.index (endsign) #---finished printing
                    Gets the string print File02[startindex:endindex] Getword=file02[startindex:endindex] #---The string to be intercepted---newword=unicode (getword, ' utf-8 ') #---
                    Write the first column of the table---gettable.write (index,0,index+1) #---Write to the second column of the table--- Gettable.write (Index,1,newword) #---Number of rows from 1---index+=1 #---Determine if the table exists---I F Os.path.isfile (Filepath+ '/wordxls.xls '): Os.remove (filepath+ '/wordxls.xls ') getwordexcel.save (filepath+ '/wordxls.xls ')
 

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.