Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: UTF-8 -*-
- __author__ = 'Chernov.Artem'
- import os
- class FileHelper:
- @staticmethod
- def read(path):
- """
- Function read data from file
- :param pathToFile: absolut path to file
- :return:
- """
- if not os.path.isfile(path):
- raise Exception('File {0} not found'.format(path))
- with open(path, 'r', encoding='utf-8') as f:
- toReturn = [line.strip() for line in f if line.strip() != '']
- if not len(toReturn):
- raise Exception('File "' + path + '" empty')
- return toReturn
- @staticmethod
- def write(path, data, mode='w'):
- """
- Function for write data to file
- :param path: absolut path to file
- :param data: data which need saving to file
- :param mode: mode for file
- :return:
- """
- if type(data) == list:
- data = "\n".join(data)
- with open(path, mode, encoding="utf-8") as f:
- f.write(data + '\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement