''' 功能:查看文件 版本:1.0 作者:白 ''' import sys,os try : filename = sys.argv[ 1 ] try : f = open (filename) except IOError: print ( "\033[33mThis is Files is not exist\033[0m" ) sys.exit() while True : line = f.readline() if len (line) = = 0 : break else : line = line.strip() print (line) f.close() except IndexError: print ( "\033[33mUsage: python example.py 1.txt|filename \033[0m" ) except FileNotFoundError: print ( "\033[33m文件不存在,请输入正确的文件名 \033[0m" ) |