我正在尝试创建一个类树,我可以从中创建各种文件并插入值列表。我只包含了分隔文件的代码。在运行以下代码的同时,我收到标题中显示的消息,请提供帮助。谢谢
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,','))