Exemple #1
0
def import_json(file, path=''):
    with open(get_file(file, path=path), 'r') as f:
        try:
            return json.load(f)
        except:
            return {}
Exemple #2
0
def export_json(data, file, path='', indent=2):
    with open(get_file(file, path=path), 'w') as f:
        json.dump(data, f, indent=indent)
Exemple #3
0
def get_file_string(file, path='', encoding='utf-8'):
	with open(get_file(file, path=path), 'r', encoding=encoding) as f:
		return f.read()
Exemple #4
0
def append_file_lines(file, path='', lines=[], newline='\n', encoding='utf-8'):
	with open(get_file(file, path=path), 'a', encoding=encoding) as f:
		f.writelines(lines_gen(lines=lines, newline=newline))
		return True
Exemple #5
0
def append_file_string(file, path='', text='', encoding='utf-8'):
	with open(get_file(file, path=path), 'a', encoding=encoding) as f:
		f.write(text)
		return True
Exemple #6
0
def get_file_lines(file, path='', newline='\n', encoding='utf-8'):
	with open(get_file(file, path=path), 'r', encoding=encoding) as f:
		return [l.rstrip(newline) for l in f]