学习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-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门