陈年椰子
```python
def file_view(file_name,line_num):
number = line_num.split(':')
count=0
with open(file_name,encoding='utf-8') as f1:
count=len(f1.readlines())
f = open(file_name,encoding='utf-8')
if number[0]=='' and number[1]=='':
print('\n%s文件全文的内容如下:\n'%(file_name))
for i in range(count):
print(f.readline(),end='')
elif number[0]=='' and number[1]!='':
print('\n文件%s从开始到%s行的内容如下:\n'%(file_name,number[1]))
for i in range(int(number[1])):
print(f.readline(),end='')
f.close()
elif number[0]!='' and number[1]=='':
print('\n文件%s从%s行到末尾的内容如下:\n'%(file_name,number[0]))
for i in range(count):
if i >= int(number[0])-1:
print(f.readline(),end='')
else:
f.readline()
f.close()
else:
print('\n文件%s从%s行到%s行的内容如下:\n'%(file_name,number[0],number[1]))
for i in range(count):
if i >= int(number[0])-1 and i<= int(number[1])-1:
print(f.readline(),end='')
f.close()
file_name = input(r'请输入要打开的文件(C:\test.txt):')
line_num = input('请输入需要显示的行数【格式如13:21或:21或21:】:')
file_view(file_name,line_num)
```@