terte 发表于 2018-4-9 11:49:50

python 脚本实现查看文件内容



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'''
功能:查看文件
版本:1.0
作者:白
'''
import sys,os
try:
    filename=sys.argv
    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")



页: [1]
查看完整版本: python 脚本实现查看文件内容