提示用户输入内容内容后,应该是一边输入,一边保存,不要等到用户全部输入到内存再进行保存.

    1. def register(username, user_pwd, usercount={'userin': 1}):
    2. # 把用户名和密码写入文件
    3. # 文件如果存在则追加,不存在则创建
    4. file_path = makepath.get_filepath(__file__, 1, '用户注册表信息.xlsx')
    5. if os.path.exists(file_path):
    6. wb = load_workbook(file_path)
    7. sheet = wb.worksheets[0]
    8. new_postion = sheet.max_row + 1
    9. if not sheet['A1'].value:
    10. new_postion -=1
    11. else:
    12. wb = workbook.Workbook()
    13. sheet = wb.worksheets[0]
    14. new_postion = 1
    15. user_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    16. for column, value in enumerate([username, user_pwd, user_time], 1):
    17. sheet.cell(new_postion, column).value = value
    18. wb.save(file_path)
    19. print('第{}次完成录入'.format(usercount['userin']))
    20. usercount['userin'] += 1
    21. return register

    这里在用户输入用户名密码后, 直接创建文件,进行保存