def write_file(file_path, file_content): if file_path.find('/') != -1: father_dir = '/'.join(file_path.split('/')[0:-1]) if not os.path.exists(father_dir): os.makedirs(father_dir) file_object = open(file_path, 'w') file_object.write(file_content) file_object.close()