This article mainly introduces the characters that need to be found in the Python System Disk for searching. It involves the skills related to the Python character search and has some reference value, for more information, see the following example. Share it with you for your reference. The details are as follows:
'''Created on 2011-7-13 @ author: 123 ''' import OS # Save the current disk def existdisk (): curdisks = [] allDisks = ['C: ', 'd: ', 'e:', 'f: ', 'G:', 'H: ',' I: ', 'J:', 'K :', \ 'l: ','m:', 'N': ', 'O:', 'P: ', 'q:', 'r: ','s: ', 't:', \ 'U:', 'v: ', 'W:', 'x: ', 'y:', 'z :', 'A: ',' B: '] for disk in allDisks: if OS. path. exists (disk): curdisks. append (disk) return curdisks # The directory contains the searched character def SearchDirFile (path, src): if not OS. path. ex Ists (path): print "% s path does not exist" % path for root, dirs, files in OS. walk (path, True): if-1! = Root. find (src): # Whether the character print root for item in files: path = OS. path. join (root, item) if-1 exists in the path name! = Path. find (src): # print path of the character to be searched in the file list # find the def SearchFile (path, src) in the file content: if not OS. path. exists (path): print "% s path does not exist" % path for root, dirs, files in OS. walk (path, True): for item in files: path = OS. path. join (root, item) try: f = open (path, 'R') for eachline in f. readlines (): if-1! = Eachline. find (src): # whether the text content contains the print path f. close () break failed T: pass # Check whether the def SearchAllDirFile (src): curdisks = existdisk () for disk in curdisks is found in all the current disk directories: disk = disk + '\' SearchDirFile (disk, src) print "complete search" # Find whether all files in the current disk directory contain the characters def SearchALLFile (src ): curdisks = existdisk () for disk in curdisks: disk = disk + "\" SearchFile (disk, src) print "complete search" SearchALLFile ('convert decimal to binary ')
I hope this article will help you with Python programming.