質問編集履歴
1
・・・の箇所を追加したコードになります。
test
CHANGED
File without changes
|
test
CHANGED
@@ -206,11 +206,115 @@
|
|
206
206
|
|
207
207
|
|
208
208
|
|
209
|
+
class FileType(abc.ABC):
|
210
|
+
|
211
|
+
@abc.abstractclassmethod
|
212
|
+
|
213
|
+
def lines(self, file_path):
|
214
|
+
|
209
|
-
|
215
|
+
pass
|
216
|
+
|
217
|
+
|
218
|
+
|
210
|
-
|
219
|
+
#------------------------------------途中-------------------------------------
|
220
|
+
|
221
|
+
class Write(FileType):
|
222
|
+
|
223
|
+
def __init__(self, args : dict):
|
224
|
+
|
225
|
+
self._file_path = args.get('file_path', test_path)
|
226
|
+
|
227
|
+
self._file_mode = args.get('file_mode', 'w')
|
228
|
+
|
229
|
+
self._file_contens = []
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
def lines(self):
|
234
|
+
|
235
|
+
with FileAccess(self._file_path) as file:
|
236
|
+
|
237
|
+
self._file_contens = file._writelines()
|
238
|
+
|
239
|
+
return self._file_contens
|
240
|
+
|
241
|
+
#-----------------------------------------------------------------------------
|
242
|
+
|
243
|
+
class Read(FileType):
|
244
|
+
|
245
|
+
def __init__(self, args_1, args_2):
|
246
|
+
|
247
|
+
self._file_path = args_1
|
248
|
+
|
249
|
+
self._file_mode = args_2
|
250
|
+
|
251
|
+
self._file_contens = []
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
def lines(self):
|
256
|
+
|
257
|
+
with FileAccess(self._file_path) as file:
|
258
|
+
|
259
|
+
self._file_contens = file._readlines()
|
260
|
+
|
261
|
+
return self._file_contens
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
class FileAccess(object):
|
268
|
+
|
269
|
+
def __init__(self, file_path):
|
270
|
+
|
271
|
+
self._file_path = file_path
|
272
|
+
|
273
|
+
self._file = None
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
def _open(self):
|
278
|
+
|
279
|
+
self._file = open(self._file_path)
|
280
|
+
|
281
|
+
#self._file = open(test_path)
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
def _close(self):
|
286
|
+
|
287
|
+
self._file.close()
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
def __enter__(self):
|
292
|
+
|
211
|
-
.
|
293
|
+
self._open()
|
294
|
+
|
212
|
-
|
295
|
+
return self
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
300
|
+
|
213
|
-
.
|
301
|
+
self._close()
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
def _readlines(self):
|
306
|
+
|
307
|
+
file_read_contens = self._file.readlines()
|
308
|
+
|
309
|
+
return file_read_contens
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
def _writelines(self):
|
314
|
+
|
315
|
+
file_write_contens = self._file.writelines()
|
316
|
+
|
317
|
+
return file_write_contens
|
214
318
|
|
215
319
|
|
216
320
|
|