model.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:OpenCool 作者: arkharin 项目源码 文件源码
def save(data, file_name, folder='', home_path=Path.home()):
    fp = Path(home_path, folder)
    while True:
        if fp.exists():
            break
        else:
            user_input = input("This folder doesn't exist. Do you want create it? [yes]/no: ")
            if _user_decision(user_input):
                fp.mkdir()
                break
            else:
                folder = input('Write new name: ')
                fp = Path(home_path, folder)

    fp = Path(home_path, folder, file_name + _EXTENSION)
    while True:
        if fp.exists():
            if fp.is_dir():
                print("It's a folder, not a file")
                _user_decision('yes')
            else:
                user_input = input('This file already exists. Do you want rename it? [yes]/no: ')
            if _user_decision(user_input):
                name = input('Write new file name: ')
                fp = Path(home_path, folder, name)
            else:
                break
        else:
            break

    print('File saved in: ', fp)
    # Save
    fp = fp.open('w')
    json.dump(data, fp, indent=4, ensure_ascii=False, sort_keys=True)
    fp.close()
    print('Save successfully!')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号