笨方法学习Python-习题15: 读取文件
来源:互联网 发布:淘宝联盟 微信遭投诉 编辑:程序博客网 时间:2024/06/06 01:32
"""我们已经学习了input和argv,只有多做练习才能明白其工作原理。这节练习设计到了两个文件,一个是ex15.py,另一个是ex15_sample.txt,内容如下:This is stuff I typed into a file.It is really cool stuff.Lots and lots of fun to have in here."""# coding=utf-8# 导入模组from sys import argv# 定义变量script,filename = argv# 打开文件,可以在Windows命令窗口输入 python -m pydoc opentxt = open(filename)# 打印print("Here's your file %r:" % filename)# 读取文件内容并打印print(txt.read())txt.close()# 打印“Type the filename again:”print("Type the filename again:")# 输入文件名file_again = input("> ")# 打开文件txt_again = open(file_again)# 读取文件内容并打印print(txt_again.read())txt_again.close()"""1.txt and txt_again 变量执行一下 close() ,处理完文件后你需要将其关闭,这是很重要的一点。2.from sys import argv 是什么意思? sys 是一个代码库,是从库里取出 argv 这个功能来3.总结下节练习的知识点:open(),close(),read()方法,以及argv和input()方法的加深使用"""
阅读全文
0 0
- 笨方法学习Python-习题15: 读取文件
- 笨方法学Python 习题 15: 读取文件
- 笨办法学python习题15 读取文件
- 笨方法学习Python-习题16: 读写文件
- 笨方法学习Python-习题17: 更多文件操作
- 习题15 读取文件
- 习题15--读取文件
- 笨方法学习Python-习题11:提问
- 笨方法学习Python-习题42: 物以类聚
- 笨方法学习Python-习题43、44
- python文件读取方法
- 笨方法学Python 习题 16: 读写文件
- 笨方法学Python 习题 17: 更多文件操作
- 《笨方法学Python》学习笔记--习题1
- 《笨方法学python》习题43的学习笔记
- 笨方法学习Python-习题3:数字和数学计算
- 笨方法学习Python-习题4:变量(variable)和命名
- 笨方法学习Python-习题6:字符串(string)和文本
- Matlab Excel服务器,笔记
- AudioFlinger Binder Struct Chart
- 由三边求三角形面积
- Spring Boot 集成Redis
- 黑板架构风格
- 笨方法学习Python-习题15: 读取文件
- run custom shell script '[cp] copy pods resource
- JDK7中ReentrantReadWriteLock源码解析(2)
- 阿里云vpc+nat网关+路由表的详解
- 系统日志输出工具类
- systemctl命令
- 枚举---枚举的其他应用
- JDK7中ReentrantReadWriteLock源码解析(3)
- 简单的delegate代理使用