学习python第n'''天——我在看笨办法学python(读取文件)
这是读取文件的内容
This is stuff I typed into a file.
It is really cool stuff.
Lots and lots of fun to have in here.
这是代码
from sys import argv
script, filename = argv
print(f" Here 's your file { filename }:")
txt=open(filename).read()
print(txt)
print(" Type the filename again:")
file_name = input("> ")
txt_again = open(file_name)
print(txt_again.read( ))
这是运行结果
PS C:\Users\HH\lpthw> python ex4.py ex4_sample.txt
Here 's your file ex4_sample.txt:
This is stuff I typed into a file.
It is really cool stuff.
Lots and lots of fun to have in here.
Type the filename again:
> ex4_sample.txt
This is stuff I typed into a file.
It is really cool stuff.
Lots and lots of fun to have in here.
浙公网安备 33010602011771号