Python-stdin-stdout

print("===========================sys模块的使用===============================") import sys #sys.stdin 接收用户的输入,读取键盘输入的数据 #sys.stdout 标准输出 #sys.stderr 错误输出 s_in = sys.stdin #while True: #content = s_in.readline().rstrip("\n") #写1行 #hello\n ==> hello ==> \n #cc = s_in.readline() #写1行 #hello\n #if cc == "out\n": # print("退出") #break #print(type(cc),cc) #print("-----")# #以上程序没有问题,是 VScode的问题 #标准输出,改变输出位置,改控制台输出变为输出(写)到文件 sys.stdout = open("Pfile/Pfile12.txt","w",encoding="utf8") print("Hello") print("Hello world") #标准error输出,改变输出位置,改控制台输出变为输出(写)到文件 #err ==> error sys.stderr = open("Pfile/error.txt","w",encoding="utf8") print(1 / 0) #表示错误,error,错误日志
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章