## bdfr - Add the bound instance as method parameter - Change methods not using its bound instance to staticmethods - Fix dangerous default argument - Refactor the comparison involving `not` - Refactor unnecessary `else` / `elif` when `if` block has a `raise` statement - Refactor unnecessary `else` / `elif` when `if` block has a `return` statement - Refactor useless `else` block in the loop - Remove implicit `object` from the base class - Remove reimported module - Remove unnecessary generator - Remove unnecessary return statement - Remove unnecessary use of comprehension - Remove unused imports - Use `is` to compare type of objects - Using not x can cause unwanted results ## Dockerfile - use a pinned Python version tag instead of latest - leverage cached requirements Signed-off-by: Vladislav Doster <mvdoster@gmail.com> Co-authored-by: Ali Parlakçı <parlakciali@gmail.com>
26 lines
677 B
Python
26 lines
677 B
Python
from os import path
|
|
|
|
|
|
class Store:
|
|
def __init__(self, directory=None):
|
|
self.directory = directory
|
|
if self.directory:
|
|
if path.exists(directory):
|
|
with open(directory, 'r') as f:
|
|
self.list = f.read().split("\n")
|
|
else:
|
|
with open(self.directory, 'a'):
|
|
pass
|
|
self.list = []
|
|
else:
|
|
self.list = []
|
|
|
|
def __call__(self):
|
|
return self.list
|
|
|
|
def add(self, data):
|
|
self.list.append(data)
|
|
if self.directory:
|
|
with open(self.directory, 'a') as f:
|
|
f.write("{data}\n".format(data=data))
|