This article brings you a brief introduction to the installation method of python and IO programming. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
一.python installation
1.python IDLE
Download official website: www.python.org
Note: After selecting When installing components, check all components, pay special attention to check pip and Add python.exe to Path
2.pycharm
Download official website: https://www.jetbrains.com/pycharm/
A Python IDE created by JetBrains, which also supports Google App Engine, IronPython
3.Anaconda
Download official website: https://www.anaconda.com/ download/
An open source Python distribution, including a large number of installed scientific packages such as: numpy, pandas, etc.
2. IO programming
1. File reading and writing
Open the file:
The mode parameter in the open function:
## The buffering parameters in the open function:File reading and writing: Frequently used methods include read(), readlines() ,write(),close()
try: f = open("D:/Python/test.txt","r+") # 'r+' == r+w(可读可写,文件若不存在就报错(IOError)) print(f.read()) f.write("def") f.seek(0,0) # 把文件指针从末尾移到开头 print(f.read()) finally: if f: f.close()
with open("D:/Python/test.txt","r+") as f: print(f.read()) f.write("def") f.seek(0,0) print(f.read())
import pickle d = dict(url="index.html",title="首页",content="首页")print(pickle.dumps(d)) with open("D:/Python/test.txt","wb") as f: pickle.dump(d,f)
with open("D:/Python/test.txt","rb") as f: d = pickle.load(f)print(d) d = pickle.loads(b'\x80\x03}q\x00(X\x03\x00\x00\x00urlq\x01X\n\x00\x00\x00index.htmlq\x02X\x05\x00\x00\x00titleq\x03X\x06\x00\x00\x00\xe9\xa6\x96\xe9\xa1\xb5q\x04X\x07\x00\x00\x00contentq\x05h\x04u.')print(d)
The above is the entire content of this article, about For more exciting content on python, you can pay attention to the
Python video tutorialand python article tutorial columns on the php Chinese website! ! !
The above is the detailed content of python installation method and a brief introduction to IO programming. For more information, please follow other related articles on the PHP Chinese website!