加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ex20.py 674 Bytes
一键复制 编辑 原始数据 按行查看 历史
TianTianZaoChen 提交于 2020-01-29 21:05 . With Python3 refactoring code
from sys import argv
script, input_file = argv
def print_all(f):
print(f.read())
# seek(n) to read a file's content from byte-n
def rewind(f):
f.seek(0)
def print_a_line(line_count, f):
print(line_count, f.readline())
current_file = open(input_file)
print("First let's print the whole file:\n")
print_all(current_file)
print("Now let's rewind, kind of like a tape.")
rewind(current_file)
print("Let's print three lines:")
current_line = 1
print_a_line(current_line, current_file)
current_line = current_line + 1
print_a_line(current_line, current_file)
current_line = current_line + 1
print_a_line(current_line, current_file)
current_file.close()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化