Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文件读写方法的优化 #39

Open
linzi1994 opened this issue Apr 4, 2019 · 0 comments
Open

文件读写方法的优化 #39

linzi1994 opened this issue Apr 4, 2019 · 0 comments

Comments

@linzi1994
Copy link

linzi1994 commented Apr 4, 2019

Is your feature request related to a problem? Please describe. 描述对应的教程内容
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
简洁有效的描述教程内出现的漏洞或问题。
以下三个有更简单的命令or方法
①:查看Python or pip 版本
②:查看/安装环境依赖包
③:文件的读写
Describe the solution you'd like 说出你的解决建议
A clear and concise description of what you want to happen. 描述你想实现的内容。
①:查看Python or pip 版本
直接使用python -V 可以查看Python版本(注意空格 - 加大写的V)
直接使用pip -V 可以查看pip版本(注意空格 - 加大写的V)
②:查看/安装环境依赖包
查看环境依赖包:pip list 或者 pip freeze
保存环境依赖包:pip freeze > requests.txt
安装环境依赖包:pip install -r requests.txt(上一步冻结的包文件)
③:文件的读写
使用open()函数读写文件,有可能会抛出IOError的错误,一旦出错,后面的f.close()就不会调用,所以一般为了正确关闭,会使用try...finally实现。但是这样写太麻烦了,所以python里面有个with语句,来自动调用close()方法
读文件:
with open("./a.txt", "r") as f:
content = f.read()
写文件:
with open("./b.txt", "w") as f:
f.write("hello world")
Describe alternatives you've considered 如果你有其他想法,可以在此补充
A clear and concise description of any alternative solutions or features you've considered.

Additional context 其他内容
Add any other context or screenshots about the feature request here. 添加你认为有必要的内容,否则不写。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant