import json

filename = 'username.json'

try: with open(filename) as f: username = json.load(f) except FileNotFoundError: username = input('What is your name? ') with open(filename, 'w') as f: json.dump(username, f) print(f'We'll remember you when you come back, {username}!') else: print(f'Welcome back, {username}!')

Python 用户名存储示例:使用 JSON 文件

原文地址: https://www.cveoy.top/t/topic/lra7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录