Python教程

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

本文主要是介绍学习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(更多的文件操作)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!