Coastharukun 2016-08-14 02:50 采纳率: 0%
浏览 1691

【Python求解】readline()函数问题

from sys import argv

script, in_file = argv

def print_all(f):
return f.read()

def rewind(f):
return f.seek(0)

def print_line_by_line(line_count, f):
return line_count, f.readline()

txt = open(in_file)

print "First, print all of the input file."
print print_all(txt)

print "Let us rewind it."
rewind(txt)

print "print line by line."

current_line = 1
print print_line_by_line(current_line, txt)

current_line = current_line + 1
print print_line_by_line(current_line, txt)

current_line = current_line + 1
print print_line_by_line(current_line, txt)

[问题]:print_line_by_line函数里的,为什么要有line_count变量,它是怎么起作用的?

  • 写回答

1条回答 默认 最新

  • Vincent WongBin 2016-08-14 13:06
    关注

    哥啊!写python代码咱能好好写缩进吗!这么执行直接肯定报错啊! 打眼一看这个line_count 是为了记录行号。

    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教