I'm trying to create a class tree from which I can create various files and insert a list of values.I have only included code for the Delimited file. Whilst running the below code,I get the message that appears in the title, please assist.Thanks
from datetime import datetime as Dt
from abc import abstractmethod,ABCMeta
class FileWriter(metaclass=ABCMeta):
def __init__(self,FileName):
self.FileName = FileName
@staticmethod
def return_time():
return Dt.now().strftime('%Y-%m-%d %H:%M')
@abstractmethod
def write(self):
return
def format_string(self,Values,Seperator,CSV = False):
self.Values = Seperator.join((Values))
if CSV == True:self.Values = Seperator.join((Values))
return self.Values
def write_lines(self,Values,Seperator = ","):
print(self.Values)
File = open(self.FileName,'w')
File.write(self.Values + '\n')
File.close()
class DelimitedFile(FileWriter):
def __init__(self, FileName):
return super().__init__(FileName)
def format_string(self, Values, Seperator):
self.Values = Values
self.Seperator = Seperator
for i in range(len(self.Values)):
if "," in self.Values[i]:self.Values[i] = ('"' + self.Values[i] + '"')
self.Seperator = Seperator
return super().format_string(Values, Seperator) + ','
def write(self,Values,Seperator=',',CSV = False):
self.Values = str(Values)
self.Seperator = Seperator
self.Values = format_string(self.Values,self.Seperator)
super().write_lines(self.Values,Seperator=',')
NewInst = DelimitedFile('Test.txt')
print(NewInst.return_time())
Values = ['s','str','trtyh','yutyuty','u7u7u7u7','e5ryru,tut','u7u7tussth','y5syyjuyju']
NewInst.write(Values)
Value = (NewInst.format_string(Values,','))