学习python第n+1天——我在看笨办法学python(更多的文件操作)
2021/12/6 20:47:13
本文主要是介绍学习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(更多的文件操作)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-18初探Python股票自动化交易:入门指南
- 2024-09-18Python量化入门:轻松掌握量化分析基础与实战
- 2024-09-18Python量化交易:入门指南与实践
- 2024-09-18Python量化交易:入门指南与实战技巧
- 2024-09-14Python人工智能项目实战:从零开始的实践指南
- 2024-09-14探索Python人工智能资料:初学者的指南
- 2024-09-14Python人工智能资料:初学者的全面指南
- 2024-09-13Matplotlib入门:轻松绘制Python数据可视化图表
- 2024-09-13Python人工智能:初学者的入门指南
- 2024-09-13Python人工智能:轻松入门与实践