したがって、file_stringのすべての部分の末尾から「\n」を削除したいと思います。例外があり、最後の値には'\n'が含まれていないようです。これが私のコードです:
class Code(object):
def __init__(self):
pass
def open_file(self,file):
infile = open(file, 'r')
self.infile = infile.readlines()
def run(self,file):
self.file_string = []
self.open_file(file)
for i in self.infile:
self.file_string.append(i)
return self.file_string
私が言ったように、必要なのは\n削除することだけです。
入力:
>>>a = Code()
>>>a.run('go.txt')
現在の出力:
['100\n', '200\n', '300\n', '400']
私が欲しいもの:
['100', '200', '300', '400']