学习python第n+1天——我在看笨办法学python(更多的文件操作)

这次的代码,并没有成功,现在在检查问题,也希望大家给予帮助

 

from sys import argv
from os.path import exists

script, from_file, to_file = argv

print(f"Copying from {from_file} to {to_file}")

# we  could do these two on one on one line,How?
#in_file = open (from_file)
#indata = in_file .read()#这一行暂时出问题了
in_file = open(from_file)
in_file = in_file.lower()
indata = in_file.read()

print(f"The input file is {len(indata)} bytes long")

print(f"Does the output file exist?{exists(file)}")
print("Ready,hit RETURN to continue, CTRL-C to abort.")
input()

out_file = open(to_file, 'w')
out_file .write(indata)

print("Alright, all done")

 

这是我的运行结果

PS C:\Users\HH> cd lpthw
PS C:\Users\HH\lpthw> python ex6.py ex6_test.txt ex6_b.txt
Copying from ex6_test.txt to ex6_b.txt
Traceback (most recent call last):
  File "ex6.py", line 12, in <module>
    in_file = in_file.lower()
AttributeError: '_io.TextIOWrapper' object has no attribute 'lower'
PS C:\Users\HH\lpthw> cat ex6_test.txt
this is a test file.
PS C:\Users\HH\lpthw>

这是用到的一些文件

学习python第n+1天——我在看笨办法学python(更多的文件操作)

 

上一篇:ExecutorService测试


下一篇:线程池 掌握治理线程的法宝