码迷,mamicode.com
首页 > 其他好文 > 详细

编写程序实现读取文件前几行

时间:2017-02-11 16:46:29      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:print   input   编写   显示   style   blog   编写程序   实现   read   

1 #编写程序实现读取文件前几行
2 def print_line(file_name):
3     line = int(input(请输入要显示前几行:))
4     f = open(file_name)
5     for each_line in range(0,line):
6         print(f.readline())
7 
8 file_name = input(请输入要打开的文件名:)
9 print_line(file_name)

 

编写程序实现读取文件前几行

标签:print   input   编写   显示   style   blog   编写程序   实现   read   

原文地址:http://www.cnblogs.com/themost/p/6389239.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!