Exemplo n.º 1
0
def import_json(file, path=''):
    with open(get_file(file, path=path), 'r') as f:
        try:
            return json.load(f)
        except:
            return {}
Exemplo n.º 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)
Exemplo n.º 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()
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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]