鱼C论坛

 找回密码
 立即注册
查看: 1564|回复: 2

关于rewind和seek

[复制链接]
发表于 2021-1-28 00:07:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#rewind和seek字面意思能看明白,我把有关rewind和seek的命令删去之后,变成了
python ex20.py record1.txt
First let's print the whole file:

kobe
james
harden
Now let's rewind, kind of like a tape.
Let's print three lines:
1

2

3
这两个命令存在时候 是
1 kobe

2 james

3 harden
求解一下


from sys import argv

script, input_file = argv

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

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 += 1
print_a_line(current_line, current_file)

current_line += 1
print_a_line(current_line, current_file)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-1-28 07:44:37 From FishC Mobile | 显示全部楼层
看不明白你想问什么或者你想表达什么
难道你是外国人吗,非要用英语去阐述一些事情
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-1-28 19:55:22 | 显示全部楼层
wp231957 发表于 2021-1-28 07:44
看不明白你想问什么或者你想表达什么
难道你是外国人吗,非要用英语去阐述一些事情

是照着书上打出来的,书是外国人写的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-12 10:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表