'''Get number of file rows and return specify line.get number of file rows and return specify line.'''import fileinput as _fidef file_line_counts(fn): '''Get number of file rows''' i = 0 for line in open('%s' % fn): i += 1 return idef return_file_specify_line(fn,line_num): '''Return the specify line. when you open the file does not exist,or is an empty file, or read the line more than the line of the file,this function will return 'None' ''' fobj = open('%s' % fn) i = 1 while True: if i == line_num: tmp = fobj.readline() return tmp.strip() if len(tmp) != 0 else None break else: fobj.readline() i += 1 fobj.close()