Refactored for readability.
class Solution: def __init__(self, data, filename='kumite776.txt'): self.data = data self.filename = filename def write_to_file(self): with open(self.filename, 'w') as file: file.write(self.data)
- class Solution:
def __init__(self, data, filename='kumite776.txt'): self.data, self.filename, self.file = data, filename, open(filename, 'w')def __del__(self): self.file.close()write_to_file = lambda self: self.file.write(self.data)- def __init__(self, data, filename='kumite776.txt'):
- self.data = data
- self.filename = filename
- def write_to_file(self):
- with open(self.filename, 'w') as file:
- file.write(self.data)