#!/usr/bin/python #coding=utf8 import os __doc__=""" This class is a file Utility class """ __author__="""jemygraw@gmail.com""" class FileUtil: def __init__(self,filename,mode): self.filename=filename self.mode=mode self.linesep=os.linesep def readFileIntoLine(self,withLineSep): try: data="" if withLineSep: with open(self.filename,self.mode) as fp: for each in fp: data+=each else: with open(self.filename,self.mode) as fp: for each in fp: data+=each.strip() return data except IOError ,e: raise e def readFileIntoLines(self,withLineSep): try: data=[] if withLineSep==True: with open(self.filename,self.mode) as fp: for each in fp: data.append(each) else: with open(self.filename,self.mode) as fp: for each in fp: data.append(each.strip()) return data except: raise e def writeLineIntoFile(self,data,withLineSep): try: with open(self.filename,self.mode) as fp: if withLineSep==True: fp.write(data+self.linesep) else: fp.write(data) except IOError,e: raise e def writeLinesIntoFile(self,lines,withLineSep): try: with open(self.filename,self.mode) as fp: if withLineSep==True: for each in lines: fp.write(each.strip()+self.linesep) else: for each in lines: fp.write(each.strip()) except IOError,e: raise e