The basic processing of documents
First, what is the file
File is a virtual operating system of units
Second, what is the use document
Storing data
Third, open the process file
1. Locate the file path
path =r'D:\pycharm\yjy\上海python学习\123'
# Right click the file, copy path Copy Path
2. Double-click to open
f = open(path,'w')
# R -> read-only, w -> write-only
3. See File
data = f.read()
4. Write files
f.write('xndkudghxj')
#write: write, if no files are created in advance, he will create a new file
5. Close the file
<1> del f
del f
Only removes reference to the file and the file in python memory footprint, but did not remove the occupancy of the operating system.
<2> f.close()
f.close()
Close the file of all, that will shut down the operating system takes on file.
Fourth, the absolute and relative paths
4.1 absolute path
From the beginning to take root chestnuts give
path =r'D:\pycharm\yjy\上海python学习\123'
4.2 relative path
Taken from the current folder, you can write directly to the file name, give chestnuts
path = r'test.py'