jmquintana79
1/17/2016 - 3:38 PM

Write text file class

Write text file class

# NOTE: file() is no supported in python3

class cfile(file):
    #subclass file to have a more convienient use of writeline
    def __init__(self, name, mode = 'r'):
        self = file.__init__(self, name, mode)

    def write(self, string):
        self.writelines(string + '\n')
        return None

if __name__ == "__main__":
  f = cfile('filename.txt', 'w')
  f.write('appends newline charachter')
  f.write('is written on a new line')
  f.close()