python结束程序的三种技巧

2021-03-05 14:27

阅读:340

标签:bsp   erro   cep   str   注册   pytho   with   pen   man   

1. break

2.exit(0)

3.sys.exit(0)

 

 

import file_manager
import sys


def start():
    # try:
    #     with open(‘file/welcome.txt‘,‘r‘,encoding=‘utf8‘) as f:
    #         content = f.read()
    #         while True:
    #             input(content)
    # except FileNotFoundError:
    #     print(‘文件未找到!‘)
    content = file_manager.read_file(welcome.txt)
    # file_manager.BASE_DIR = ‘./xxx/‘
    # content = file_manager.read_file(‘sss.txt‘)
    while True:
        operator = input(content + \n请输入(1-3:)
        if operator == 1:
            print(注册)
        elif operator == 2:
            print(登录)
        elif operator == 3:
            print(退出)
            # break   # 结束循环
            # exit(0)  # 退出整个程序
            sys.exit(0)  # 退出整个程序
        else:
            print(输入有误!)


if __name__ == __main__:
    start()

 

python结束程序的三种技巧

标签:bsp   erro   cep   str   注册   pytho   with   pen   man   

原文地址:https://www.cnblogs.com/2722127842qq-123/p/14324588.html


评论


亲,登录后才可以留言!